Module: MiniApi::CaseTransform
- Defined in:
- lib/mini_api/case_transform.rb
Class Method Summary collapse
- .request_params_keys(params) ⇒ Object
- .response_keys(response) ⇒ Object
- .transform(object, transform_to = :snake_case) ⇒ Object
Class Method Details
.request_params_keys(params) ⇒ Object
25 26 27 |
# File 'lib/mini_api/case_transform.rb', line 25 def request_params_keys(params) transform(params, Config.transform_params_keys_to) end |
.response_keys(response) ⇒ Object
29 30 31 |
# File 'lib/mini_api/case_transform.rb', line 29 def response_keys(response) transform(response, Config.transform_response_keys_to) end |
.transform(object, transform_to = :snake_case) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mini_api/case_transform.rb', line 10 def transform(object, transform_to = :snake_case) object.deep_transform_keys do |key| case transform_to when :camel_case key.to_s.camelize when :camel_lower key.to_s.camelize(:lower) when :snake_case key.to_s.underscore else raise CaseTransformOptionInvalid, "option #{transform_to} is not supported." end end end |