Adjusting the methods that dealt with the encoding/decoding data for attributes in ActiveRecord's :serialized_attributes hash so that it will fall back on YAML as the default serializer. Close #197

This commit is contained in:
Ben Atkins 2013-02-04 16:00:34 -05:00
parent 24339a1414
commit 9f9032ae16
2 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,8 @@
## 2.7.1 (Unreleased)
- [#197](https://github.com/airblade/paper_trail/issues/197) - PaperTrail now falls back on using YAML for serialization of
serialized model attributes for storage in the `object` and `object_changes` columns in the `Version` table. This fixes
compatibility for `Rails 3.0.x` for projects that employ the `serialize` declaration on a model.
- [#194](https://github.com/airblade/paper_trail/issues/194) - A JSON serializer is now included in the gem.
- [#192](https://github.com/airblade/paper_trail/pull/192) - `object_changes` should store serialized representation of serialized
attributes for `create` actions (in addition to `update` actions, which had already been patched by
@ -14,7 +17,7 @@
- [#183](https://github.com/airblade/paper_trail/pull/183) - Fully qualify the `Version` class to help prevent
namespace resolution errors within other gems / plugins.
- [#180](https://github.com/airblade/paper_trail/pull/180) - Store serialized representation of serialized attributes
on the `object` and `object_changes` column in the `Version` table.
on the `object` and `object_changes` columns in the `Version` table.
- [#164](https://github.com/airblade/paper_trail/pull/164) - Allow usage of custom serializer for storage of object attributes.
## 2.6.4

View File

@ -84,13 +84,19 @@ module PaperTrail
# Used for Version#object attribute
def serialize_attributes_for_paper_trail(attributes)
serialized_attributes.each do |key, coder|
attributes[key] = coder.dump(attributes[key]) if attributes.key?(key)
if attributes.key?(key)
coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump) # Rails 3.0.x's default serializers don't have a `dump` method
attributes[key] = coder.dump(attributes[key])
end
end
end
def unserialize_attributes_for_paper_trail(attributes)
serialized_attributes.each do |key, coder|
attributes[key] = coder.load(attributes[key]) if attributes.key?(key)
if attributes.key?(key)
coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump)
attributes[key] = coder.load(attributes[key])
end
end
end
@ -98,6 +104,7 @@ module PaperTrail
def serialize_attribute_changes(changes)
serialized_attributes.each do |key, coder|
if changes.key?(key)
coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump) # Rails 3.0.x's default serializers don't have a `dump` method
old_value, new_value = changes[key]
changes[key] = [coder.dump(old_value),
coder.dump(new_value)]
@ -108,6 +115,7 @@ module PaperTrail
def unserialize_attribute_changes(changes)
serialized_attributes.each do |key, coder|
if changes.key?(key)
coder = PaperTrail::Serializers::Yaml unless coder.respond_to?(:dump)
old_value, new_value = changes[key]
changes[key] = [coder.load(old_value),
coder.load(new_value)]