module TrackChanges::Model::ClassMethods

Public Instance Methods

snapshot_all() click to toggle source

Create snapshots for all records so that the next changes made are captured This can be used to init track changes on existing records

# File lib/track_changes/model.rb, line 33
def snapshot_all
  # Update existing snapshots
  joins(:snapshot).find_each {|record| record.snapshot.update }
  # Create new snapshots
  where.not(:id => joins(:snapshot)).find_each(&:create_snapshot)
end
track_changes_fields() click to toggle source

Returns the method names to call to fetch the fields tracked for changes

# File lib/track_changes/model.rb, line 23
def track_changes_fields
  fields =  Array(track_changes_options[:only]).collect(&:to_s).presence || self.attribute_names
  fields -= Array(track_changes_options[:except]).collect(&:to_s)
  fields += Array(track_changes_options[:methods]).collect(&:to_s)
  fields -= ['created_at', 'updated_at'] unless track_changes_options[:track_timestamps]
  fields -= [primary_key] unless track_changes_options[:track_primary_key]
end