Class: Torque::PostgreSQL::Adapter::OID::StructList
- Inherits:
-
Struct
- Object
- ActiveRecord::Type::Json
- Struct
- Torque::PostgreSQL::Adapter::OID::StructList
show all
- Defined in:
- lib/torque/postgresql/adapter/oid/struct_list.rb
Instance Attribute Summary
Attributes inherited from Struct
#backfill, #klass, #type
Instance Method Summary
collapse
Methods inherited from Struct
#==, #changed?, #changed_in_place?, #document, #hash, #initialize, state, #without_backfill
Instance Method Details
#blank_document ⇒ Object
38
39
40
|
# File 'lib/torque/postgresql/adapter/oid/struct_list.rb', line 38
def blank_document
[]
end
|
#cast(value) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/torque/postgresql/adapter/oid/struct_list.rb', line 8
def cast(value)
case value
when ::String then cast(parse(value))
when ::Array then value.map { |item| super(item) }
else value
end
end
|
#deserialize(value) ⇒ Object
16
17
18
19
20
|
# File 'lib/torque/postgresql/adapter/oid/struct_list.rb', line 16
def deserialize(value)
::Array.wrap(parse(value)).map do |item|
build(item, from_database: true, blank: true)
end
end
|
#document_for(value) ⇒ Object
30
31
32
|
# File 'lib/torque/postgresql/adapter/oid/struct_list.rb', line 30
def document_for(value)
::Array.wrap(value).map { |item| item.is_a?(klass) ? document(item) : item }
end
|
#empty?(value) ⇒ Boolean
34
35
36
|
# File 'lib/torque/postgresql/adapter/oid/struct_list.rb', line 34
def empty?(value)
value.is_a?(::Array) ? value.empty? : super
end
|
#serialize(value) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/torque/postgresql/adapter/oid/struct_list.rb', line 22
def serialize(value)
case value
when ::Array then value.empty? ? nil : encode(value)
when nil then nil
else super
end
end
|