From 5e2cd92688c8332cbf28606053775f6f322f7817 Mon Sep 17 00:00:00 2001 From: Tyler Rick Date: Tue, 6 Nov 2012 15:09:44 -0800 Subject: [PATCH] Slightly more efficient to loop through serialized_attributes than to loop through the changes hash --- lib/paper_trail/has_paper_trail.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 12d149b5..00cb9b80 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -185,14 +185,13 @@ module PaperTrail # The double negative (reject, !include?) preserves the hash structure of self.changes. self.changes.reject do |key, value| !notably_changed.include?(key) - end.tap do |changes_hash| + end.tap do |changes| # Use serialized value for attributes that are serialized - changes_hash.each do |key, (old_value, new_value)| - if serialized_attributes.include?(key) - # coder.dump(new_value) is the same as @attributes[key].serialized_value - coder = @attributes[key].coder - changes_hash[key] = [coder.dump(old_value), - coder.dump(new_value)] + serialized_attributes.each do |key, coder| + if changes.key?(key) + old_value, new_value = changes[key] + changes[key] = [coder.dump(old_value), + coder.dump(new_value)] end end end