Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all perceived/cyclomatic complexity rubocop offences #116

Merged
merged 1 commit into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/daru/view/adapters/googlecharts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,24 @@ def converted_type_to_js(vec_name, data_set)
end
end

# TODO : fix Metrics/PerceivedComplexity rubocop error
def return_js_type(data) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def return_js_type(data)
return if data.nil?
data = data.is_a?(Hash) ? data[:v] : data
extract_js_type(data)
end

def extract_js_type(data)
case
when data.nil?
return
when data.is_a?(String)
return 'string'
when data.is_a?(Integer) || data.is_a?(Float) || data.is_a?(BigDecimal)
return 'number'
when data.is_a?(TrueClass) || data.is_a?(FalseClass)
return 'boolean'
when data.is_a?(DateTime) || data.is_a?(Time)
return 'datetime'
'string'
when data.is_a?(Integer), data.is_a?(Float), data.is_a?(BigDecimal)
'number'
when data.is_a?(TrueClass), data.is_a?(FalseClass)
'boolean'
when data.is_a?(DateTime), data.is_a?(Time)
'datetime'
when data.is_a?(Date)
return 'date'
'date'
end
end
end
Expand Down
16 changes: 10 additions & 6 deletions lib/daru/view/adapters/highcharts/layout_helper_iruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,27 @@ def build_html_output_iruby(type, placeholder, object, &block)
encapsulate_js_iruby core_js
end

# rubocop:disable Metrics/PerceivedComplexity
def encapsulate_js_iruby(core_js)
js_output =
if request_is_xhr?
"#{js_start_iruby} #{core_js} #{js_end_iruby}"
# Turbolinks.version < 5
elsif defined?(Turbolinks) && request_is_referrer?
eventlistener_page_load(core_js)
elsif defined?(Turbolinks) && request_turbolinks_5_tureferrer?
eventlistener_turbolinks_load(core_js)
elsif defined?(Turbolinks)
encapsulate_js_for_turbolinks(core_js)
else
call_core_js(core_js)
end

defined?(raw) ? raw(js_output) : js_output
end
# rubocop:enable Metrics/PerceivedComplexity

def encapsulate_js_for_turbolinks(core_js)
if request_is_referrer?
eventlistener_page_load(core_js)
elsif request_turbolinks_5_tureferrer?
eventlistener_turbolinks_load(core_js)
end
end

def eventlistener_page_load(core_js)
<<-EOJS
Expand Down