50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/record_history/has_record_history.rb', line 50
def build_history_on_update
return if self.new_record?
self.record_history_obj = []
ignore = self.attr_ignore
self.class.new.attributes.keys.each do |attr_name|
next unless (self.send("#{attr_name}_changed?"))
next if ignore.include?(attr_name)
next if !self.class.record_history_only.blank? && !self.class.record_history_only.include?(attr_name)
next if !self.class.record_history_ignore.blank? && self.record_history_ignore.include?(attr_name)
self.record_history_obj << RecordHistoryModel.new(
:item_type => self.class.name,
:item_id => self.id,
:attr_name => attr_name,
:old_value => self.send("#{attr_name}_was"),
:new_value => self.send("#{attr_name}"),
:author => RecordHistory.author,
:transaction_id => Time.now.to_f
)
end
self.record_history_polymorphic_group.each do |attr|
next if !self.send("#{attr}_type_changed?") && !self.send("#{attr}_id_changed?")
self.record_history_obj << RecordHistoryModel.new(
:item_type => self.class.name,
:item_id => self.id,
:attr_name => attr,
:old_value => {"#{attr}_type".to_sym => self.send("#{attr}_type_was"), "#{attr}_id".to_sym => self.send("#{attr}_id_was")},
:new_value => {"#{attr}_type".to_sym => self.send("#{attr}_type"), "#{attr}_id".to_sym => self.send("#{attr}_id")},
:author => RecordHistory.author,
:transaction_id => Time.now.to_f
)
end
end
|