Class: ActiveRecord::Type::Serialized
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
|
|
| Inherits: | Object |
| Defined in: | activerecord/lib/active_record/type/serialized.rb |
Class Method Summary
Instance Attribute Summary
- #coder readonly
- #serialized? ⇒ Boolean readonly
- #subtype readonly
::ActiveModel::Type::Helpers::Mutable - Included
Instance Method Summary
- #accessor
- #assert_valid_value(value)
- #changed_in_place?(raw_old_value, value) ⇒ Boolean
- #deserialize(value)
- #force_equality?(value) ⇒ Boolean
- #serialize(value)
- #default_value?(value) ⇒ Boolean private
- #encoded(value) private
::ActiveModel::Type::Helpers::Mutable - Included
| #cast, | |
| #changed_in_place? |
|
Constructor Details
.new(subtype, coder, comparable: false) ⇒ Serialized
Instance Attribute Details
#coder (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/type/serialized.rb', line 10
attr_reader :subtype, :coder
#serialized? ⇒ Boolean (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/type/serialized.rb', line 63
def serialized? # :nodoc: true end
#subtype (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/type/serialized.rb', line 10
attr_reader :subtype, :coder
Instance Method Details
#accessor
[ GitHub ]# File 'activerecord/lib/active_record/type/serialized.rb', line 49
def accessor ActiveRecord::Store::IndifferentHashAccessor end
#assert_valid_value(value)
[ GitHub ]#changed_in_place?(raw_old_value, value) ⇒ Boolean
# File 'activerecord/lib/active_record/type/serialized.rb', line 36
def changed_in_place?(raw_old_value, value) return false if value.nil? if @comparable old_value = deserialize(raw_old_value) old_value != value else raw_new_value = encoded(value) raw_old_value.nil? != raw_new_value.nil? || subtype.changed_in_place?(raw_old_value, raw_new_value) end end
#default_value?(value) ⇒ Boolean (private)
# File 'activerecord/lib/active_record/type/serialized.rb', line 68
def default_value?(value) value == coder.load(nil) end
#deserialize(value)
[ GitHub ]# File 'activerecord/lib/active_record/type/serialized.rb', line 19
def deserialize(value) if default_value?(value) value else coder.load(super) end end
#encoded(value) (private)
[ GitHub ]# File 'activerecord/lib/active_record/type/serialized.rb', line 72
def encoded(value) return if default_value?(value) payload = coder.dump(value) if payload && @subtype.binary? ActiveModel::Type::Binary::Data.new(payload) else payload end end
#force_equality?(value) ⇒ Boolean
#serialize(value)
[ GitHub ]# File 'activerecord/lib/active_record/type/serialized.rb', line 27
def serialize(value) return if value.nil? unless default_value?(value) super coder.dump(value) end end