class Audit

Public Instance Methods

attribute_snapshot() click to toggle source
# File lib/auditor/audit.rb, line 29
def attribute_snapshot
  attributes = {}.with_indifferent_access
  self.class.modifying.trail(self).each do |predecessor|
    attributes.merge!(predecessor.new_attributes)
  end
  attributes
end

Protected Instance Methods

new_attributes() click to toggle source

Returns a hash of the changed attributes with the new values

# File lib/auditor/audit.rb, line 40
def new_attributes
  (audited_changes || {}).inject({}.with_indifferent_access) do |attrs,(attr,values)|
    attrs[attr] = values.is_a?(Array) ? values.last : values
    attrs
  end
end

Private Instance Methods

set_tenant() click to toggle source
# File lib/auditor/audit.rb, line 62
def set_tenant
  self.tenant = Auditor::Tenant.current_tenant if self.tenant_id.nil?
end
set_user() click to toggle source
# File lib/auditor/audit.rb, line 58
def set_user
  self.user = Auditor::User.current_user if self.user_id.nil?
end
set_version_number() click to toggle source
# File lib/auditor/audit.rb, line 49
def set_version_number
  max = self.class.where(
    :auditable_id => auditable_id,
    :auditable_type => auditable_type
  ).maximum(:version) || 0

  self.version = self.audited_changes == nil ? max : max + 1
end