Module: Pupper::TrackableAttributes::ClassMethods
- Defined in:
- lib/pupper/trackable_attributes.rb
Instance Method Summary collapse
Instance Method Details
#_attributes ⇒ Object
32 33 34 |
# File 'lib/pupper/trackable_attributes.rb', line 32 def _attributes @_attributes ||= [] end |
#_attributes=(attrs) ⇒ Object
36 37 38 |
# File 'lib/pupper/trackable_attributes.rb', line 36 def _attributes=(attrs) @_attributes = attrs end |
#attr_accessor(*attrs) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pupper/trackable_attributes.rb', line 40 def attr_accessor(*attrs) # override the default so that we can hook into the created methods define_attribute_methods(*attrs) _attributes << attrs attrs.each do |attr| define_method attr do attributes[attr] end define_method "#{attr}=" do |value| send("#{attr}_will_change!") unless value == send(attr) attributes[attr] = value end end end |