Module: DuckRecord::AttributeAssignment

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::ForbiddenAttributesProtection
Included in:
Base
Defined in:
lib/duck_record/attribute_assignment.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(new_attributes) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/duck_record/attribute_assignment.rb', line 14

def assign_attributes(new_attributes)
  unless new_attributes.respond_to?(:stringify_keys)
    raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
  end
  return if new_attributes.nil? || new_attributes.empty?

  attributes = new_attributes.stringify_keys
  _assign_attributes(sanitize_for_mass_assignment(attributes))
end

#attributes=(attributes) ⇒ Object

Alias for ActiveModel::AttributeAssignment#assign_attributes. See ActiveModel::AttributeAssignment.



10
11
12
# File 'lib/duck_record/attribute_assignment.rb', line 10

def attributes=(attributes)
  assign_attributes(attributes)
end