Module: Entasis::TransposeKeys
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/entasis/transpose_keys.rb
Instance Method Summary collapse
-
#attributes_with_transpose=(hash) ⇒ Object
Takes a hash of attribute names and values and set each attribute.
Instance Method Details
#attributes_with_transpose=(hash) ⇒ Object
Takes a hash of attribute names and values and set each attribute. Before trying to set the given attribute it transpose the name of that attribute from camelcased to underscored.
If strict attribute name checking is enabled it will raise an UnknownAttributeError
for that class.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/entasis/transpose_keys.rb', line 18 def attributes_with_transpose=(hash) hash.each do |name, value| transposed_name = name.to_s.dup.underscore.downcase if attribute_names.include?(transposed_name) || self.respond_to?("#{transposed_name}=") self.send("#{transposed_name}=", value) else if attributes_config[:strict] == true raise self.class::UnknownAttributeError, "unknown attribute: #{transposed_name} (transposed from #{name})" end end end end |