From 4dfd1d4fc0bf83a4567ed989bd9ca1e63234793b Mon Sep 17 00:00:00 2001 From: Ben Atkins Date: Tue, 23 Sep 2014 17:31:36 -0400 Subject: [PATCH] Serialization handler methods on PaperTrail::Model::ClassMethods should fall back to current serializer set under Config --- CHANGELOG.md | 2 ++ lib/paper_trail/has_paper_trail.rb | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c6a7356..a4f1ce3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ PaperTrail::Rails::Engine.eager_load! [#354](https://github.com/airblade/paper_trail/issues/354) / [#131](https://github.com/airblade/paper_trail/issues/131) - Versions should be built with `after_` callbacks so the timestamp field for a version can be forced to match the corresponding timestamp in the database for the state persistence of a change to the base (versioned) model. + - Methods handling serialized attributes should fallback to the currently set Serializer instead of always falling back + to `PaperTrail::Serializers::YAML`. ## 3.0.5 diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 3aa8f9d3..84f4d789 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -115,7 +115,8 @@ module PaperTrail serialized_attributes.each do |key, coder| if attributes.key?(key) - coder = PaperTrail::Serializers::YAML unless coder.respond_to?(:dump) # Fall back to YAML if `coder` has no `dump` method + # Fall back to current serializer if `coder` has no `dump` method + coder = PaperTrail.serializer unless coder.respond_to?(:dump) attributes[key] = coder.dump(attributes[key]) end end @@ -127,7 +128,7 @@ module PaperTrail serialized_attributes.each do |key, coder| if attributes.key?(key) - coder = PaperTrail::Serializers::YAML unless coder.respond_to?(:dump) + coder = PaperTrail.serializer unless coder.respond_to?(:dump) attributes[key] = coder.load(attributes[key]) end end @@ -140,7 +141,8 @@ module PaperTrail serialized_attributes.each do |key, coder| if changes.key?(key) - coder = PaperTrail::Serializers::YAML unless coder.respond_to?(:dump) # Fall back to YAML if `coder` has no `dump` method + # Fall back to current serializer if `coder` has no `dump` method + coder = PaperTrail.serializer unless coder.respond_to?(:dump) old_value, new_value = changes[key] changes[key] = [coder.dump(old_value), coder.dump(new_value)] @@ -154,7 +156,7 @@ module PaperTrail serialized_attributes.each do |key, coder| if changes.key?(key) - coder = PaperTrail::Serializers::YAML unless coder.respond_to?(:dump) + coder = PaperTrail.serializer unless coder.respond_to?(:dump) old_value, new_value = changes[key] changes[key] = [coder.load(old_value), coder.load(new_value)]