aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/type')
-rw-r--r--activerecord/lib/active_record/type/decorator.rb14
-rw-r--r--activerecord/lib/active_record/type/serialized.rb6
2 files changed, 17 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/type/decorator.rb b/activerecord/lib/active_record/type/decorator.rb
new file mode 100644
index 0000000000..9fce38ea44
--- /dev/null
+++ b/activerecord/lib/active_record/type/decorator.rb
@@ -0,0 +1,14 @@
+module ActiveRecord
+ module Type
+ module Decorator # :nodoc:
+ def init_with(coder)
+ @subtype = coder['subtype']
+ __setobj__(@subtype)
+ end
+
+ def encode_with(coder)
+ coder['subtype'] = __getobj__
+ end
+ end
+ end
+end
diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb
index 5b512433b0..17004b3593 100644
--- a/activerecord/lib/active_record/type/serialized.rb
+++ b/activerecord/lib/active_record/type/serialized.rb
@@ -2,6 +2,7 @@ module ActiveRecord
module Type
class Serialized < SimpleDelegator # :nodoc:
include Mutable
+ include Decorator
attr_reader :subtype, :coder
@@ -36,14 +37,13 @@ module ActiveRecord
end
def init_with(coder)
- @subtype = coder['subtype']
@coder = coder['coder']
- __setobj__(@subtype)
+ super
end
def encode_with(coder)
- coder['subtype'] = @subtype
coder['coder'] = @coder
+ super
end
private