diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-01 22:24:01 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-01 22:24:01 +0200 |
commit | 02ee081cd645b51cbdfb28cd305777d3257ad871 (patch) | |
tree | 1b02b3ccffbef9296aaa6660caed5c64fcb362aa /activerecord/lib/active_record/type/serialized.rb | |
parent | 260c384bdb539265b31d3937df48e528acb50800 (diff) | |
parent | 90c8be76a7d00475be5ff4db2eeedde5cc936c2d (diff) | |
download | rails-02ee081cd645b51cbdfb28cd305777d3257ad871.tar.gz rails-02ee081cd645b51cbdfb28cd305777d3257ad871.tar.bz2 rails-02ee081cd645b51cbdfb28cd305777d3257ad871.zip |
Merge pull request #15435 from sgrif/sg-rm-serialization
Remove most code related to serialized properties
Diffstat (limited to 'activerecord/lib/active_record/type/serialized.rb')
-rw-r--r-- | activerecord/lib/active_record/type/serialized.rb | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index 4052ac0fa0..eac31f6cc3 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -10,20 +10,21 @@ module ActiveRecord end def type_cast(value) - if value.respond_to?(:unserialized_value) - value.unserialized_value(super(value.value)) + if is_default_value?(value) + value else - super + coder.load(super) end end def type_cast_for_write(value) - Attribute.new(coder, value, :unserialized) + return if value.nil? + unless is_default_value?(value) + coder.dump(value) + end end - def raw_type_cast_for_write(value) - Attribute.new(coder, value, :serialized) - end + alias type_cast_for_database type_cast_for_write def serialized? true @@ -33,24 +34,10 @@ module ActiveRecord ActiveRecord::Store::IndifferentHashAccessor end - class Attribute < Struct.new(:coder, :value, :state) # :nodoc: - def unserialized_value(v = value) - state == :serialized ? unserialize(v) : value - end - - def serialized_value - state == :unserialized ? serialize : value - end - - def unserialize(v) - self.state = :unserialized - self.value = coder.load(v) - end + private - def serialize - self.state = :serialized - self.value = coder.dump(value) - end + def is_default_value?(value) + value == coder.load(nil) end end end |