10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/paper_trail-audit.rb', line 10
def calculate_audit_for(param)
objects = [{attributes: self.attributes, whodunnit: self.paper_trail.originator},
self.versions.map {|e| {attributes: YAML.load(e.object), whodunnit: e.paper_trail_originator} if e.object}.compact].flatten
objects = objects.select {|e| e[:attributes]["updated_at"]}.sort_by {|e| e[:attributes]["updated_at"]}
result = []
if(objects.count > 0 && !objects.first[:attributes][param.to_s].nil?)
result << PaperTrailAudit::Change.new({old_value: nil,
new_value: objects.first[:attributes][param.to_s],
time: objects.first[:attributes]["updated_at"],
whodunnit: objects.first[:whodunnit]
})
end
objects.each_cons(2) do |a,b|
if a[:attributes][param.to_s] != b[:attributes][param.to_s]
result << PaperTrailAudit::Change.new({old_value: a[:attributes][param.to_s],
new_value: b[:attributes][param.to_s],
time: b[:attributes]["updated_at"],
whodunnit: b[:whodunnit]
})
end
end
result
end
|