module Pupper::TrackableAttributes::ClassMethods

Public Instance Methods

_attributes() click to toggle source
# File lib/pupper/trackable_attributes.rb, line 36
def _attributes
  @_attributes ||= []
end
_attributes=(attrs) click to toggle source
# File lib/pupper/trackable_attributes.rb, line 40
def _attributes=(attrs)
  @_attributes = attrs
end
attr_accessor(*attrs) click to toggle source
# File lib/pupper/trackable_attributes.rb, line 44
def attr_accessor(*attrs)
  # override the default so that we can hook into the created methods
  define_attribute_methods(*attrs)

  _attributes.concat(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