Module: Formable::Params
- Defined in:
- lib/formable/params.rb
Class Method Summary collapse
- .camelize_key(key) ⇒ Object
- .camelize_keys(value) ⇒ Object
- .compact(hash) ⇒ Object
- .encode_path(value) ⇒ Object
- .iso8601(value) ⇒ Object
- .json_body(hash) ⇒ Object
Class Method Details
.camelize_key(key) ⇒ Object
41 42 43 |
# File 'lib/formable/params.rb', line 41 def camelize_key(key) key.to_s.gsub(/_([a-z\d])/) { ::Regexp.last_match(1).upcase } end |
.camelize_keys(value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/formable/params.rb', line 24 def camelize_keys(value) case value when Array value.map { |item| camelize_keys(item) } when Hash value.each_with_object({}) do |(key, item), result| result[camelize_key(key)] = camelize_keys(item) end else value end end |
.compact(hash) ⇒ Object
20 21 22 |
# File 'lib/formable/params.rb', line 20 def compact(hash) hash.reject { |_, value| value.nil? } end |
.encode_path(value) ⇒ Object
9 10 11 |
# File 'lib/formable/params.rb', line 9 def encode_path(value) URI.encode_uri_component(value) end |
.iso8601(value) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/formable/params.rb', line 13 def iso8601(value) return if value.nil? return value.iso8601 if value.respond_to?(:iso8601) value.to_s end |
.json_body(hash) ⇒ Object
37 38 39 |
# File 'lib/formable/params.rb', line 37 def json_body(hash) compact(camelize_keys(hash)) end |