| Class | Audit |
| In: |
lib/acts_as_audited/audit.rb
|
| Parent: | ActiveRecord::Base |
Audit saves the changes to ActiveRecord models. It has the following attributes:
| user= | -> | user_as_model= |
| user_as_string= | -> | user= |
| user | -> | user_as_model |
| user_as_string | -> | user |
All audits made during the block called will be recorded as made by user. This method is hopefully threadsafe, making it ideal for background operations that require audit information.
# File lib/acts_as_audited/audit.rb, line 32
32: def self.as_user(user, &block)
33: Thread.current[:acts_as_audited_user] = user
34:
35: yield
36:
37: Thread.current[:acts_as_audited_user] = nil
38: end
# File lib/acts_as_audited/audit.rb, line 95
95: def self.assign_revision_attributes(record, attributes)
96: attributes.each do |attr, val|
97: if record.respond_to?("#{attr}=")
98: record.attributes.has_key?(attr.to_s) ?
99: record[attr] = val :
100: record.send("#{attr}=", val)
101: end
102: end
103: record
104: end
# File lib/acts_as_audited/audit.rb, line 22
22: def self.audited_classes
23: self.audited_class_names.map(&:constantize)
24: end
# File lib/acts_as_audited/audit.rb, line 86
86: def self.reconstruct_attributes(audits)
87: attributes = {}
88: result = audits.collect do |audit|
89: attributes.merge!(audit.new_attributes).merge!(:version => audit.version)
90: yield attributes if block_given?
91: end
92: block_given? ? result : attributes
93: end
# File lib/acts_as_audited/audit.rb, line 64
64: def ancestors
65: self.class.find(:all, :order => 'version',
66: :conditions => ['auditable_id = ? and auditable_type = ? and version <= ?',
67: auditable_id, auditable_type, version])
68: end
Returns a hash of the changed attributes with the new values
# File lib/acts_as_audited/audit.rb, line 71
71: def new_attributes
72: (audit_changes || {}).inject({}.with_indifferent_access) do |attrs,(attr,values)|
73: attrs[attr] = Array(values).last
74: attrs
75: end
76: end
Returns a hash of the changed attributes with the old values
# File lib/acts_as_audited/audit.rb, line 79
79: def old_attributes
80: (audit_changes || {}).inject({}.with_indifferent_access) do |attrs,(attr,values)|
81: attrs[attr] = Array(values).first
82: attrs
83: end
84: end