class Audit
Public Instance Methods
attribute_snapshot()
click to toggle source
# File lib/auditor/audit.rb, line 27 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 38 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_user()
click to toggle source
# File lib/auditor/audit.rb, line 56 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 47 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