Class: Appstats::Audit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Appstats::Audit
- Defined in:
- lib/appstats/audit.rb
Class Method Summary collapse
- .audit_create(obj, options = {}) ⇒ Object
- .audit_destroy(obj, options = {}) ⇒ Object
- .audit_update(obj, options = {}) ⇒ Object
Class Method Details
.audit_create(obj, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/appstats/audit.rb', line 10 def self.audit_create(obj, = {}) count = 0 return count unless auditable?(obj) table_name = obj.class.table_name obj_name = obj.class.name count += save_audit(obj, { :action => "created"}, ) obj.attributes.each do |obj_attr,new_value| next if new_value.nil? old_value = nil count += save_audit(obj, { :action => "created", :obj_attr => obj_attr, :old_value => old_value, :new_value => new_value }, ) end count end |
.audit_destroy(obj, options = {}) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/appstats/audit.rb', line 37 def self.audit_destroy(obj, = {}) count = 0 return count unless auditable?(obj) count += save_audit(obj, { :action => "destroyed" }, ) count end |
.audit_update(obj, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/appstats/audit.rb', line 26 def self.audit_update(obj, = {}) count = 0 return count unless auditable?(obj) obj.changed_attributes.each do |obj_attr,old_value| new_value = obj.send("#{obj_attr}") count += save_audit(obj, { :action => "updated", :obj_attr => obj_attr, :old_value => old_value, :new_value => new_value}, ) end count end |