Class: ActiveRecord::Type::Serialized
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- ActiveRecord::Type::Serialized
- Includes:
- ActiveModel::Type::Helpers::Mutable
- Defined in:
- lib/active_record/type/serialized.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#coder ⇒ Object
readonly
Returns the value of attribute coder.
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
Instance Method Summary collapse
- #accessor ⇒ Object
- #assert_valid_value(value) ⇒ Object
- #changed_in_place?(raw_old_value, value) ⇒ Boolean
- #deserialize(value) ⇒ Object
-
#initialize(subtype, coder) ⇒ Serialized
constructor
A new instance of Serialized.
- #inspect ⇒ Object
- #serialize(value) ⇒ Object
Constructor Details
#initialize(subtype, coder) ⇒ Serialized
Returns a new instance of Serialized.
8 9 10 11 12 |
# File 'lib/active_record/type/serialized.rb', line 8 def initialize(subtype, coder) @subtype = subtype @coder = coder super(subtype) end |
Instance Attribute Details
#coder ⇒ Object (readonly)
Returns the value of attribute coder.
6 7 8 |
# File 'lib/active_record/type/serialized.rb', line 6 def coder @coder end |
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
6 7 8 |
# File 'lib/active_record/type/serialized.rb', line 6 def subtype @subtype end |
Instance Method Details
#accessor ⇒ Object
40 41 42 |
# File 'lib/active_record/type/serialized.rb', line 40 def accessor ActiveRecord::Store::IndifferentHashAccessor end |
#assert_valid_value(value) ⇒ Object
44 45 46 47 48 |
# File 'lib/active_record/type/serialized.rb', line 44 def assert_valid_value(value) if coder.respond_to?(:assert_valid_value) coder.assert_valid_value(value) end end |
#changed_in_place?(raw_old_value, value) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/active_record/type/serialized.rb', line 33 def changed_in_place?(raw_old_value, value) return false if value.nil? raw_new_value = encoded(value) raw_old_value.nil? != raw_new_value.nil? || subtype.changed_in_place?(raw_old_value, raw_new_value) end |
#deserialize(value) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/active_record/type/serialized.rb', line 14 def deserialize(value) if default_value?(value) value else coder.load(super) end end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/active_record/type/serialized.rb', line 29 def inspect Kernel.instance_method(:inspect).bind(self).call end |
#serialize(value) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/active_record/type/serialized.rb', line 22 def serialize(value) return if value.nil? unless default_value?(value) super coder.dump(value) end end |