module TrackChanges::Model::InstanceMethods

Private Instance Methods

persist_tracked_changes() click to toggle source

Compares the last tracked changes to the current state and saves a diff of the changes

# File lib/track_changes/model.rb, line 49
def persist_tracked_changes
  return if track_changes == false

  new_record = id_was.blank?
  action     = new_record ? 'create' : 'update'
  changes_by = track_changes_by.is_a?(ActiveRecord::Base) ? track_changes_by.id : track_changes_by

  if snapshot
    snapshot.create_diff(:action => action, :changes_by => changes_by)
    snapshot.update
  elsif new_record
    create_snapshot
    snapshot.create_diff(:action => action, :changes_by => changes_by, :from => {}, :to => snapshot.state)
  else # We started tracking changes after the item was created
    create_snapshot
    snapshot.create_diff(:action => action, :changes_by => changes_by, :from => {})
  end
end
track_changes_by() click to toggle source
# File lib/track_changes/model.rb, line 44
def track_changes_by
  @track_changes_by || TrackChanges.default_attribution
end