Module: Auditing::Base::InstanceMethods
- Defined in:
- lib/auditing/base.rb
Instance Method Summary collapse
- #class_exists?(class_name) ⇒ Boolean
- #log_association_create(child_object, hash) ⇒ Object
- #log_association_destroy(item) ⇒ Object
- #log_association_update(child_object, hash) ⇒ Object
- #log_creation ⇒ Object
- #log_update ⇒ Object
Instance Method Details
#class_exists?(class_name) ⇒ Boolean
71 72 73 74 75 76 |
# File 'lib/auditing/base.rb', line 71 def class_exists?(class_name) klass = Module.const_get(class_name) return klass.is_a?(Class) rescue NameError return false end |
#log_association_create(child_object, hash) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/auditing/base.rb', line 47 def log_association_create(child_object, hash) add_audit(:action => 'added', :association => child_object, :field_name => hash[:field], :old_value => Marshal.dump(nil), :new_value => Marshal.dump(hash[:value].to_s) ) end |
#log_association_destroy(item) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/auditing/base.rb', line 63 def log_association_destroy(item) mark_as_undoable = audits.where({:association_id => item.id, :association_type => item.class.to_s}) mark_as_undoable.each do |i| i.update_attribute('undoable', false) end add_audit(:action => 'removed', :association => item, :undoable => false) end |
#log_association_update(child_object, hash) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/auditing/base.rb', line 55 def log_association_update(child_object, hash) add_audit(:action => 'updated', :association => child_object, :field_name => hash[:field], :old_value => Marshal.dump(hash[:old_value].to_s), :new_value => Marshal.dump(hash[:new_value].to_s) ) end |
#log_creation ⇒ Object
31 32 33 |
# File 'lib/auditing/base.rb', line 31 def log_creation add_audit(:action => 'created', :undoable => false) end |
#log_update ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/auditing/base.rb', line 35 def log_update if changed? changes.each.select {|k,v| auditing_fields.include?(k)}.each do |field, change| next if change[0].to_s == change[1].to_s add_audit(:action => 'updated', :field_name => field, :old_value => Marshal.dump(change[0]), :new_value => Marshal.dump(change[1]) ) end end end |