From ebe485fd8ec80a1a9b86516bc6f74bc5bbba3476 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Feb 2011 11:41:14 -0800 Subject: serialize can take an arbitrary code object --- activerecord/lib/active_record/base.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index f66b84935c..5310b55a92 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -536,7 +536,13 @@ module ActiveRecord #:nodoc: # serialize :preferences # end def serialize(attr_name, class_name = Object) - serialized_attributes[attr_name.to_s] = Coders::YAMLColumn.new(class_name) + coder = if [:load, :dump].all? { |x| class_name.respond_to?(x) } + class_name + else + Coders::YAMLColumn.new(class_name) + end + + serialized_attributes[attr_name.to_s] = coder end # Guesses the table name (in forced lower-case) based on the name of the class in the -- cgit v1.2.3