Module: WellRested::Utils
- Extended by:
- GenericUtils, Utils
- Defined in:
- lib/well_rested/utils.rb
Instance Method Summary collapse
-
#objects_to_attributes(obj) ⇒ Object
Turn any nested resources back into hashes before sending them.
Methods included from GenericUtils
Instance Method Details
#objects_to_attributes(obj) ⇒ Object
Turn any nested resources back into hashes before sending them
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/well_rested/utils.rb', line 9 def objects_to_attributes(obj) if obj.respond_to?(:attributes_for_api) obj.attributes_for_api elsif obj.kind_of?(Hash) new_attributes = {}.with_indifferent_access obj.each do |k, v| new_attributes[k] = objects_to_attributes(v) end new_attributes elsif obj.kind_of?(Array) obj.map { |e| self.objects_to_attributes(e) } else obj #raise "Attributes was not a Hash or Enumerable" end end |