Module: FoundationApi::Model::AttributeMethods::ClassMethods
- Defined in:
- lib/foundation_api/model/attribute_methods.rb
Instance Method Summary collapse
- #alias_attribute(new_name, old_name) ⇒ Object
- #map_attribute(attr) ⇒ Object
- #reverse_map_attribute(attr) ⇒ Object
- #translate_attributes(attrs) ⇒ Object
Instance Method Details
#alias_attribute(new_name, old_name) ⇒ Object
14 15 16 |
# File 'lib/foundation_api/model/attribute_methods.rb', line 14 def alias_attribute(new_name, old_name) self.attribute_aliases = attribute_aliases.merge(new_name.to_s => old_name.to_s) end |
#map_attribute(attr) ⇒ Object
18 19 20 |
# File 'lib/foundation_api/model/attribute_methods.rb', line 18 def map_attribute(attr) attribute_aliases[attr.to_s] || attr.to_s end |
#reverse_map_attribute(attr) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/foundation_api/model/attribute_methods.rb', line 21 def reverse_map_attribute(attr) if v = attribute_aliases.rassoc(attr.to_s) v[0].to_s else attr.to_s end end |
#translate_attributes(attrs) ⇒ Object
28 29 30 |
# File 'lib/foundation_api/model/attribute_methods.rb', line 28 def translate_attributes(attrs) HashWithIndifferentAccess[attrs.collect { |attr,value| [map_attribute(attr), value] }] end |