Module: Pupper::TrackableAttributes::ClassMethods

Defined in:
lib/pupper/trackable_attributes.rb

Instance Method Summary collapse

Instance Method Details

#_attributesObject



36
37
38
# File 'lib/pupper/trackable_attributes.rb', line 36

def _attributes
  @_attributes ||= []
end

#_attributes=(attrs) ⇒ Object



40
41
42
# File 'lib/pupper/trackable_attributes.rb', line 40

def _attributes=(attrs)
  @_attributes = attrs
end

#attr_accessor(*attrs) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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