Module: ActiveModel::Datastore::TrackChanges::ClassMethods
- Defined in:
- lib/active_model/datastore/track_changes.rb
Instance Method Summary collapse
-
#enable_change_tracking(*attributes) ⇒ Object
Enables track changes functionality for the provided attributes using ActiveModel::Dirty.
Instance Method Details
#enable_change_tracking(*attributes) ⇒ Object
Enables track changes functionality for the provided attributes using ActiveModel::Dirty.
Calls define_attribute_methods for each attribute provided.
Creates a setter for each attribute that will look something like this:
def name=(value)
name_will_change! unless value == @name
@name = value
end
Overrides tracked_attributes to return an Array of the attributes configured for tracking.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/active_model/datastore/track_changes.rb', line 108 def enable_change_tracking(*attributes) attributes = attributes.collect(&:to_sym) attributes.each do |attr| define_attribute_methods attr define_method("#{attr}=") do |value| send("#{attr}_will_change!") unless value == instance_variable_get("@#{attr}") instance_variable_set("@#{attr}", value) end end define_method('tracked_attributes') { attributes } end |