Module: Hashie::Extensions::Dash::PropertyTranslation::InstanceMethods
- Defined in:
- lib/hashie/extensions/dash/property_translation.rb
Instance Method Summary collapse
-
#[]=(property, value) ⇒ Object
Sets a value on the Dash in a Hash-like way.
-
#initialize_attributes(attributes) ⇒ Object
Deletes any keys that have a translation.
-
#property_exists?(property) ⇒ Boolean
Raises an NoMethodError if the property doesn't exist.
Instance Method Details
#[]=(property, value) ⇒ Object
Sets a value on the Dash in a Hash-like way.
Note: Only works on pre-existing properties.
134 135 136 137 138 139 140 141 142 |
# File 'lib/hashie/extensions/dash/property_translation.rb', line 134 def []=(property, value) if self.class.translation_exists? property send("#{property}=", value) elsif self.class.transformation_exists? property super property, self.class.transformed_property(property, value) elsif property_exists? property super end end |
#initialize_attributes(attributes) ⇒ Object
Deletes any keys that have a translation
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/hashie/extensions/dash/property_translation.rb', line 145 def initialize_attributes(attributes) return unless attributes attributes_copy = attributes.dup.delete_if do |k, v| if self.class.translations_hash.include?(k) self[k] = v true end end super attributes_copy end |
#property_exists?(property) ⇒ Boolean
Raises an NoMethodError if the property doesn't exist
157 158 159 160 |
# File 'lib/hashie/extensions/dash/property_translation.rb', line 157 def property_exists?(property) fail_no_property_error!(property) unless self.class.property?(property) true end |