Slightly more efficient to loop through serialized_attributes than to loop through the changes hash
This commit is contained in:
parent
ae2350b147
commit
5e2cd92688
|
@ -185,14 +185,13 @@ module PaperTrail
|
||||||
# The double negative (reject, !include?) preserves the hash structure of self.changes.
|
# The double negative (reject, !include?) preserves the hash structure of self.changes.
|
||||||
self.changes.reject do |key, value|
|
self.changes.reject do |key, value|
|
||||||
!notably_changed.include?(key)
|
!notably_changed.include?(key)
|
||||||
end.tap do |changes_hash|
|
end.tap do |changes|
|
||||||
# Use serialized value for attributes that are serialized
|
# Use serialized value for attributes that are serialized
|
||||||
changes_hash.each do |key, (old_value, new_value)|
|
serialized_attributes.each do |key, coder|
|
||||||
if serialized_attributes.include?(key)
|
if changes.key?(key)
|
||||||
# coder.dump(new_value) is the same as @attributes[key].serialized_value
|
old_value, new_value = changes[key]
|
||||||
coder = @attributes[key].coder
|
changes[key] = [coder.dump(old_value),
|
||||||
changes_hash[key] = [coder.dump(old_value),
|
coder.dump(new_value)]
|
||||||
coder.dump(new_value)]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue