Class: ActiveRecord::Type::Serialized
Overview
Instance Attribute Summary collapse
Attributes inherited from Value
#limit, #precision, #scale
Instance Method Summary
collapse
Methods included from Mutable
#type_cast_from_user
Methods inherited from Value
#==, #binary?, #changed?, #hash, #klass, #number?, #text?, #type, #type_cast_for_schema, #type_cast_from_user
Constructor Details
#initialize(subtype, coder) ⇒ Serialized
Returns a new instance of Serialized.
9
10
11
12
13
|
# File 'lib/active_record/type/serialized.rb', line 9
def initialize(subtype, coder)
@subtype = subtype
@coder = coder
super(subtype)
end
|
Instance Attribute Details
#coder ⇒ Object
Returns the value of attribute coder.
7
8
9
|
# File 'lib/active_record/type/serialized.rb', line 7
def coder
@coder
end
|
#subtype ⇒ Object
Returns the value of attribute subtype.
7
8
9
|
# File 'lib/active_record/type/serialized.rb', line 7
def subtype
@subtype
end
|
Instance Method Details
#changed_in_place?(raw_old_value, value) ⇒ Boolean
34
35
36
37
38
39
|
# File 'lib/active_record/type/serialized.rb', line 34
def changed_in_place?(raw_old_value, value)
return false if value.nil?
raw_new_value = type_cast_for_database(value)
raw_old_value.nil? != raw_new_value.nil? ||
subtype.changed_in_place?(raw_old_value, raw_new_value)
end
|
#encode_with(coder) ⇒ Object
50
51
52
53
|
# File 'lib/active_record/type/serialized.rb', line 50
def encode_with(coder)
coder['coder'] = @coder
super
end
|
#init_with(coder) ⇒ Object
45
46
47
48
|
# File 'lib/active_record/type/serialized.rb', line 45
def init_with(coder)
@coder = coder['coder']
super
end
|
#inspect ⇒ Object
30
31
32
|
# File 'lib/active_record/type/serialized.rb', line 30
def inspect
Kernel.instance_method(:inspect).bind(self).call
end
|
#type_cast_for_database(value) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/active_record/type/serialized.rb', line 23
def type_cast_for_database(value)
return if value.nil?
unless default_value?(value)
super coder.dump(value)
end
end
|
#type_cast_from_database(value) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/active_record/type/serialized.rb', line 15
def type_cast_from_database(value)
if default_value?(value)
value
else
coder.load(super)
end
end
|