Class: ActiveRecord::Type::Serialized
Overview
Instance Attribute Summary collapse
#limit, #precision, #scale
Instance Method Summary
collapse
#cast
#==, #binary?, #cast, #changed?, #hash, #map, #type, #type_cast_for_schema, #value_constructed_by_mass_assignment?
Constructor Details
#initialize(subtype, coder) ⇒ Serialized
Returns a new instance of Serialized.
12
13
14
15
16
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 12
def initialize(subtype, coder)
@subtype = subtype
@coder = coder
super(subtype)
end
|
Instance Attribute Details
Returns the value of attribute coder
10
11
12
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 10
def coder
@coder
end
|
Returns the value of attribute subtype
10
11
12
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 10
def subtype
@subtype
end
|
Instance Method Details
#assert_valid_value(value) ⇒ Object
48
49
50
51
52
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 48
def assert_valid_value(value)
if coder.respond_to?(:assert_valid_value)
coder.assert_valid_value(value, action: "serialize")
end
end
|
#changed_in_place?(raw_old_value, value) ⇒ Boolean
37
38
39
40
41
42
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 37
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
18
19
20
21
22
23
24
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 18
def deserialize(value)
if default_value?(value)
value
else
coder.load(super)
end
end
|
#force_equality?(value) ⇒ Boolean
54
55
56
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 54
def force_equality?(value)
coder.respond_to?(:object_class) && value.is_a?(coder.object_class)
end
|
33
34
35
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 33
def inspect
Kernel.instance_method(:inspect).bind(self).call
end
|
#serialize(value) ⇒ Object
26
27
28
29
30
31
|
# File 'activerecord/lib/active_record/type/serialized.rb', line 26
def serialize(value)
return if value.nil?
unless default_value?(value)
super coder.dump(value)
end
end
|