lib/her/model/attributes.rb
# Assign new attributes to a resource
#
# @example
#   class User
#     include Her::Model
#   end
#
#   user = User.find(1) # => #<User id=1 name="Tobias">
#   user.assign_attributes(name: "Lindsay")
#   user.changes # => { :name => ["Tobias", "Lindsay"] }
Assign new attributes to a resource
Assign new attributes to a resource
def assign_attributes(new_attributes)
        @attributes ||= attributes
        unset_attributes = self.class.use_setter_methods(self, new_attributes)
        parsed_attributes = self.class.parse_associations(unset_attributes)
        @attributes.merge!(parsed_attributes)
      end
def assign_attributes ( new_attributes ) @attributes ||= attributes unset_attributes = self . class . use_setter_methods ( self , new_attributes ) parsed_attributes = self . class . parse_associations ( unset_attributes ) @attributes . merge! ( parsed_attributes ) end
Assign new attributes to a resource
Assign new attributes to a resource
# Use setter methods first # Then translate attributes of associations into association instances # Then merge the parsed_data into @attributes.
new_attributes
<not_specific>
example
class User include Her::Model end user = User.find(1) # => # user.assign_attributes(name: "Lindsay") user.changes # => { :name => ["Tobias", "Lindsay"] }
class User include Her :: Model end user = User . find ( 1 ) # = > # user . assign_attributes ( name : " Lindsay " ) user . changes # = > { : name = > [ " Tobias " " Lindsay " ] }