Method: AttrJson::Model#assign_attributes
- Defined in:
- lib/attr_json/model.rb
#assign_attributes(new_attributes) ⇒ Object
ActiveModel method, called in initialize. overridden. from https://github.com/rails/rails/blob/42a16a4d6514f28e05f1c22a5f9125d194d9c7cb/activemodel/lib/active_model/attribute_assignment.rb
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/attr_json/model.rb', line 307 def assign_attributes(new_attributes) if !new_attributes.respond_to?(:stringify_keys) raise ArgumentError, "When assigning attributes, you must pass a hash as an argument." end return if new_attributes.empty? # stringify keys just like https://github.com/rails/rails/blob/4f99a2186479d5f77460622f2c0f37708b3ec1bc/activemodel/lib/active_model/attribute_assignment.rb#L34 new_attributes.stringify_keys.each do |k, v| setter = :"#{k}=" if respond_to?(setter) public_send(setter, v) else _attr_json_write_unknown_attribute(k, v) end end end |