Module: Granite::Form::Model::Representation::PrependMethods

Defined in:
lib/granite/form/model/representation.rb

Instance Method Summary collapse

Instance Method Details

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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/granite/form/model/representation.rb', line 17

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