Class: ReeMapper::Array
- Inherits:
-
AbstractWrapper
show all
- Defined in:
- lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb
Instance Attribute Summary
#subject
Instance Method Summary
collapse
#initialize
Instance Method Details
#cast(value, role: nil, fields_filters: nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb', line 42
def cast(value, role: nil, fields_filters: nil)
if !check_value(value)
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
end
if subject.fields_filter
fields_filters = if fields_filters
fields_filters + [subject.fields_filter]
else
[subject.fields_filter]
end
end
value.map.with_index do |item, idx|
next nil if item.nil? && subject.null
subject.type.cast(item, role:, fields_filters:)
rescue ReeMapper::ErrorWithLocation => e
e.prepend_field_name(idx.to_s)
e.location ||= subject.location
raise e
end
end
|
#db_dump(value, role: nil, fields_filters: nil) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb', line 73
def db_dump(value, role: nil, fields_filters: nil)
if !check_value(value)
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
end
if subject.fields_filter
fields_filters = if fields_filters
fields_filters + [subject.fields_filter]
else
[subject.fields_filter]
end
end
value.map.with_index do |item, idx|
next nil if item.nil? && subject.null
subject.type.db_dump(item, role:, fields_filters:)
rescue ReeMapper::ErrorWithLocation => e
e.prepend_field_name(idx.to_s)
e.location ||= subject.location
raise e
end
end
|
#db_load(value, role: nil, fields_filters: nil) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb', line 104
def db_load(value, role: nil, fields_filters: nil)
if !check_value(value)
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
end
if subject.fields_filter
fields_filters = if fields_filters
fields_filters + [subject.fields_filter]
else
[subject.fields_filter]
end
end
value.map.with_index do |item, idx|
next nil if item.nil? && subject.null
subject.type.db_load(item, role:, fields_filters:)
rescue ReeMapper::ErrorWithLocation => e
e.prepend_field_name(idx.to_s)
e.location ||= subject.location
raise e
end
end
|
#serialize(value, role: nil, fields_filters: nil) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/wrappers/array.rb', line 11
def serialize(value, role: nil, fields_filters: nil)
if !check_value(value)
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
end
if subject.fields_filter
fields_filters = if fields_filters
fields_filters + [subject.fields_filter]
else
[subject.fields_filter]
end
end
value.map.with_index do |item, idx|
next nil if item.nil? && subject.null
subject.type.serialize(item, role:, fields_filters:)
rescue ReeMapper::ErrorWithLocation => e
e.prepend_field_name(idx.to_s)
e.location ||= subject.location
raise e
end
end
|