Module: TrackChanges::Model::ClassMethods

Defined in:
lib/track_changes/model.rb

Instance Method Summary collapse

Instance Method Details

#snapshot_allObject

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



33
34
35
36
37
38
# 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_fieldsObject

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



23
24
25
26
27
28
29
# 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