module ActiveModel::Datastore::TrackChanges::ClassMethods

Public Instance Methods

enable_change_tracking(*attributes) click to toggle source

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.

# 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