Class: Appstats::Audit

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/appstats/audit.rb

Class Method Summary collapse

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, options = {})
  count = 0
  return count unless auditable?(obj)
  
  table_name = obj.class.table_name
  obj_name = obj.class.name

  count += save_audit(obj, { :action => "created"}, options)
  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 }, options)
  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, options = {})
  count = 0
  return count unless auditable?(obj)
  count += save_audit(obj, { :action => "destroyed" }, options)
  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, options = {})
  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}, options)
  end
  count
end