Module: ActiveData::Model::Representation::PrependMethods

Defined in:
lib/active_data/model/representation.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(attrs) ⇒ Object Also known as: attributes=



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_data/model/representation.rb', line 15

def assign_attributes(attrs)
  if self.class.represented_attributes.present?
    attrs = attrs.to_unsafe_hash if attrs.respond_to?(:to_unsafe_hash)
    attrs = attrs.stringify_keys
    represented_attrs = self.class.represented_names_and_aliases
      .each_with_object({}) do |name, result|
        result[name] = attrs.delete(name) if attrs.key?(name)
      end

    super(attrs.merge!(represented_attrs))
  else
    super(attrs)
  end
end