Class: OliveBranch::Transformations

Inherits:
Object
  • Object
show all
Defined in:
lib/olive_branch/middleware.rb

Class Method Summary collapse

Class Method Details

.camelize(string) ⇒ Object



29
30
31
# File 'lib/olive_branch/middleware.rb', line 29

def camelize(string)
  string.underscore.camelize(:lower)
end

.dasherize(string) ⇒ Object



33
34
35
# File 'lib/olive_branch/middleware.rb', line 33

def dasherize(string)
  string.dasherize
end

.pascalize(string) ⇒ Object



25
26
27
# File 'lib/olive_branch/middleware.rb', line 25

def pascalize(string)
  string.underscore.camelize(:upper)
end

.transform(value, transform_method) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/olive_branch/middleware.rb', line 16

def transform(value, transform_method)
  case value
  when Array then value.map { |item| transform(item, transform_method) }
  when Hash then value.deep_transform_keys! { |key| transform(key, transform_method) }
  when String then transform_method.call(value)
  else value
  end
end

.underscore_params(env) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/olive_branch/middleware.rb', line 37

def underscore_params(env)
  req = ActionDispatch::Request.new(env)
  req.request_parameters
  req.query_parameters

  env["action_dispatch.request.request_parameters"].deep_transform_keys!(&:underscore)
  env["action_dispatch.request.query_parameters"].deep_transform_keys!(&:underscore)
end