Module: Rack::DevInsight::Camelizer

Defined in:
lib/rack/dev_insight/utils/camelizer.rb

Class Method Summary collapse

Class Method Details

.camelize_keys(value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/rack/dev_insight/utils/camelizer.rb', line 8

def camelize_keys(value)
  case value
  when Array
    value.map { |v| camelize_keys(v) }
  when Hash
    value.transform_keys { |key| to_camel_case(key.to_s) }.transform_values { |v| camelize_keys(v) }
  else
    value
  end
end

.to_camel_case(str) ⇒ Object



19
20
21
# File 'lib/rack/dev_insight/utils/camelizer.rb', line 19

def to_camel_case(str)
  str.gsub(/_([a-z])/) { ::Regexp.last_match(1).upcase }
end