6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/dm-is-audited/is/audited/model.rb', line 6
def audit (*fields, &block)
audited_attributes = fields.collect { |name| properties[name] }
before :save do
@audited_original_attributes = original_attributes.dup.delete_if { |key, value| !audited_attributes.include?(key) }
@audited_new_record = new?
end
after :save do
self.instance_exec(@audited_new_record ? :create : :update, &block) if !changes.empty? || @audited_new_record
end
after :destroy do
self.instance_exec(:destroy, &block)
end
end
|