Skip to content

Commit

Permalink
Merge pull request #116 from Prakriti-nith/rubocop
Browse files Browse the repository at this point in the history
Fixed all perceived/cyclomatic complexity rubocop offences
  • Loading branch information
Shekharrajak authored Aug 15, 2018
2 parents 1d178bc + c054656 commit 9d19aed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
26 changes: 14 additions & 12 deletions lib/daru/view/adapters/googlecharts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,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

0 comments on commit 9d19aed

Please sign in to comment.