Module: Audited::Audit
- Defined in:
- lib/audited/audit.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#new_attributes ⇒ Object
Returns a hash of the changed attributes with the new values.
-
#old_attributes ⇒ Object
Returns a hash of the changed attributes with the old values.
-
#revision ⇒ Object
Return an instance of what the object looked like at this revision.
Instance Method Details
#new_attributes ⇒ Object
Returns a hash of the changed attributes with the new values
70 71 72 73 74 75 |
# File 'lib/audited/audit.rb', line 70 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 |
#old_attributes ⇒ Object
Returns a hash of the changed attributes with the old values
78 79 80 81 82 83 84 |
# File 'lib/audited/audit.rb', line 78 def old_attributes (audited_changes || {}).inject({}.with_indifferent_access) do |attrs,(attr,values)| attrs[attr] = Array(values).first attrs end end |
#revision ⇒ Object
Return an instance of what the object looked like at this revision. If the object has been destroyed, this will be a new record.
62 63 64 65 66 67 |
# File 'lib/audited/audit.rb', line 62 def revision clazz = auditable_type.constantize (clazz.find_by_id(auditable_id) || clazz.new).tap do |m| self.class.assign_revision_attributes(m, self.class.reconstruct_attributes(ancestors).merge({ :version => version })) end end |