Module: Her::Model::Attributes::ClassMethods
- Defined in:
- lib/her_extension/model/attributes.rb
Instance Method Summary collapse
-
#attributes(*attributes) ⇒ Object
Define the attributes that will be used to track dirty attributes and validations.
Instance Method Details
#attributes(*attributes) ⇒ Object
Define the attributes that will be used to track dirty attributes and validations
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/her_extension/model/attributes.rb', line 18 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 |