Module: Audited::Audit
- Defined in:
- lib/audited/audit.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
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.
Class Method Details
.included(klass) ⇒ Object
3 4 5 6 |
# File 'lib/audited/audit.rb', line 3 def self.included(klass) klass.extend(ClassMethods) klass.setup_audit end |
Instance Method Details
#new_attributes ⇒ Object
Returns a hash of the changed attributes with the new values
76 77 78 79 80 81 |
# File 'lib/audited/audit.rb', line 76 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
84 85 86 87 88 89 90 |
# File 'lib/audited/audit.rb', line 84 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.
68 69 70 71 72 73 |
# File 'lib/audited/audit.rb', line 68 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 |