lib/her/model/attributes.rb
# Define the attributes that will be used to track dirty attributes and validations
#
# @param [Array] attributes
# @example
#   class User
#     include Her::Model
#     attributes :name, :email
#   end
Define the attributes that will be used to track dirty attributes and validations
Define the attributes that will be used to track dirty attributes and validations
def attributes(*attributes)
          define_attribute_methods attributes
          attributes.each do |attribute|
            attribute = attribute.to_sym
            unless instance_methods.include?(:"#{attribute}=")
              define_method("#{attribute}=") do |value|
                @attributes[:"#{attribute}"] = nil unless @attributes.include?(:"#{attribute}")
                self.send(:"#{attribute}_will_change!") if @attributes[:"#{attribute}"] != value
                @attributes[:"#{attribute}"] = value
              end
            end
            unless instance_methods.include?(:"#{attribute}?")
              define_method("#{attribute}?") do
                @attributes.include?(:"#{attribute}") && @attributes[:"#{attribute}"].present?
              end
            end
          end
        end
def attributes ( * attributes ) define_attribute_methods attributes attributes . each do | attribute | attribute = attribute . to_sym unless instance_methods . include? ( :" #{ attribute } = " ) define_method ( "#{attribute}=" ) do | value | @attributes [ :" #{ attribute } " ] = nil unless @attributes . include? ( :" #{ attribute } " ) self . send ( :" #{ attribute } _will_change! " ) if @attributes [ :" #{ attribute } " ] != value @attributes [ :" #{ attribute } " ] = value end end unless instance_methods . include? ( :" #{ attribute } ? " ) define_method ( "#{attribute}?" ) do @attributes . include? ( :" #{ attribute } " ) && @attributes [ :" #{ attribute } " ] . present? end end end end
Define the attributes that will be used to track dirty attributes and validations
Define the attributes that will be used to track dirty attributes and validations
attributes
None
example
class User include Her::Model attributes :name, :email end
class User include Her :: Model attributes : name : email end