isomorfeus-data 2.5.2 → 2.5.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73175d7dc425cc54e235ee9719bacaaebe93b60753794949506cb044d05a5599
|
4
|
+
data.tar.gz: 1af87ebf47618289399a3cdf7539e533577f09ae0757cae9e5f7b873e3f05b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fe59f656951f87f9382f4dfd2b86b00ba835644e69b729d51cc1eef6dbec9ca13a05e683d655cb085e536d1f13d0e738c42b15309e4ba681102e1d54bbca5ad
|
7
|
+
data.tar.gz: c2403b92cb3c88e1f38d05270afef98610694d8edd8cfca274735e4b456cfae2d2902db9512737dbd7316427dd7579d8f2275c691e64d6ac31e4c77affb725c4
|
@@ -3,6 +3,16 @@ module Isomorfeus
|
|
3
3
|
module FieldSupport
|
4
4
|
def self.included(base)
|
5
5
|
base.instance_exec do
|
6
|
+
@@object_validation_proc = proc do |v|
|
7
|
+
fail = false
|
8
|
+
if v.is_a?(Array)
|
9
|
+
v.each { |e| fail = true unless e.nil? || e.is_a?(LucidObject::Mixin) }
|
10
|
+
elsif !v.nil? && !v.is_a?(LucidObject::Mixin)
|
11
|
+
fail = true
|
12
|
+
end
|
13
|
+
raise "must be nil, a LucidObject::Mixin or a Array of LucidObject::Mixin" if fail
|
14
|
+
end
|
15
|
+
|
6
16
|
def field_types
|
7
17
|
# determines how the item is stored in the index
|
8
18
|
@field_types ||= {}
|
@@ -14,6 +24,7 @@ module Isomorfeus
|
|
14
24
|
end
|
15
25
|
|
16
26
|
def field_conditions
|
27
|
+
# conditions for validating the field data
|
17
28
|
@field_conditions ||= {}
|
18
29
|
end
|
19
30
|
|
@@ -43,7 +54,7 @@ module Isomorfeus
|
|
43
54
|
alias embed attribute
|
44
55
|
|
45
56
|
def object(name, options = {})
|
46
|
-
default_options = {
|
57
|
+
default_options = { validate_block: @@object_validation_proc }
|
47
58
|
field(name, :object, default_options.merge(options))
|
48
59
|
end
|
49
60
|
alias reference object
|
@@ -64,9 +75,13 @@ module Isomorfeus
|
|
64
75
|
field_types[obj_name] == :object
|
65
76
|
end
|
66
77
|
|
78
|
+
def validate_field!(field_name, val)
|
79
|
+
raise "no such field" unless field?(field_name)
|
80
|
+
Isomorfeus::Props::Validator.new(self.name, field_name, val, field_conditions[field_name]).validate!
|
81
|
+
end
|
82
|
+
|
67
83
|
def valid_field?(field_name, val)
|
68
|
-
|
69
|
-
false
|
84
|
+
validate_field!(field_name, val)
|
70
85
|
rescue
|
71
86
|
false
|
72
87
|
end
|
@@ -84,6 +99,7 @@ module Isomorfeus
|
|
84
99
|
rescue
|
85
100
|
false
|
86
101
|
end
|
102
|
+
alias valid_embed? valid_attribute?
|
87
103
|
|
88
104
|
def valid_object?(obj_name, val)
|
89
105
|
return valid_field?(obj_name, val) if object?(obj_name)
|
@@ -91,6 +107,7 @@ module Isomorfeus
|
|
91
107
|
rescue
|
92
108
|
false
|
93
109
|
end
|
110
|
+
alias valid_reference? valid_object?
|
94
111
|
|
95
112
|
def validate
|
96
113
|
Isomorfeus::Props::ValidateHashProxy.new
|
@@ -183,7 +200,14 @@ module Isomorfeus
|
|
183
200
|
path = @_store_path + [name]
|
184
201
|
sid_or_array = Redux.fetch_by_path(*path)
|
185
202
|
return nil if `(sid_or_array === null)`
|
186
|
-
|
203
|
+
if sid_or_array[0].is_a?(String)
|
204
|
+
@_objects[name] = Isomorfeus.instance_from_sid(sid_or_array)
|
205
|
+
elsif sid_or_array[0].is_a?(Array)
|
206
|
+
a = sid_or_array.map { |sid| Isomorfeus.instance_from_sid(sid) if sid }
|
207
|
+
a.compact!
|
208
|
+
@_objects[name] = a
|
209
|
+
end
|
210
|
+
@_objects[name]
|
187
211
|
end
|
188
212
|
|
189
213
|
def fields
|
@@ -196,7 +220,10 @@ module Isomorfeus
|
|
196
220
|
def _get_selected_fields
|
197
221
|
sel_fields = fields.dup
|
198
222
|
self.class.field_types.each do |field, type|
|
199
|
-
|
223
|
+
if type == :object
|
224
|
+
v = sel_fields[field]
|
225
|
+
sel_fields[field] = v.is_a?(Array) ? v.map(&:sid) : v&.sid
|
226
|
+
end
|
200
227
|
end
|
201
228
|
sel_fields
|
202
229
|
end
|
@@ -229,7 +256,8 @@ module Isomorfeus
|
|
229
256
|
if options[:server_only]
|
230
257
|
sel_fields.delete(field_s)
|
231
258
|
elsif ft[field] == :object
|
232
|
-
|
259
|
+
v = sel_fields[field_s]
|
260
|
+
sel_fields[field_s] = v.is_a?(Array) ? v.map(&:sid) : v&.sid
|
233
261
|
end
|
234
262
|
end
|
235
263
|
sel_fields
|
@@ -20,6 +20,7 @@ module Isomorfeus
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def object_from_ref(ref, already_loaded)
|
23
|
+
return nil if !ref || ref.empty?
|
23
24
|
_, iso, type_class_name, key = ref.split('---')
|
24
25
|
raise "not a valid object reference '#{ref}'" unless iso == "iso-object-reference"
|
25
26
|
raise "invalid data class #{type_class_name}" unless Isomorfeus.valid_data_class_name?(type_class_name)
|
@@ -99,15 +100,30 @@ module Isomorfeus
|
|
99
100
|
def unserialize_or_load(v, t, already_loaded)
|
100
101
|
return unserialize(v) if t == :attribute
|
101
102
|
if t == :object && v
|
102
|
-
|
103
|
-
|
103
|
+
if v.is_a?(Array)
|
104
|
+
v = v.map { |e| object_from_ref(e, already_loaded) }
|
105
|
+
v.compact!
|
106
|
+
return v
|
107
|
+
else
|
108
|
+
return nil if v.empty?
|
109
|
+
return object_from_ref(v, already_loaded)
|
110
|
+
end
|
104
111
|
end
|
105
112
|
v
|
106
113
|
end
|
107
114
|
|
108
115
|
def serialize_or_save(v, t, already_saved)
|
109
116
|
return serialize(v) if t == :attribute
|
110
|
-
|
117
|
+
if t == :object && v
|
118
|
+
if v.is_a?(Array)
|
119
|
+
v = v.compact
|
120
|
+
v.map! { |e| create_or_save(e, already_saved) }
|
121
|
+
v.compact!
|
122
|
+
return v
|
123
|
+
else
|
124
|
+
return create_or_save(v, already_saved)
|
125
|
+
end
|
126
|
+
end
|
111
127
|
v
|
112
128
|
end
|
113
129
|
|
@@ -39,9 +39,16 @@ module LucidObject
|
|
39
39
|
if type == :object
|
40
40
|
v = f[field]
|
41
41
|
if v
|
42
|
-
|
43
|
-
|
44
|
-
data_hash.deep_merge!(v.included_items_to_transport)
|
42
|
+
if v.is_a?(LucidObject::Mixin)
|
43
|
+
data_hash.deep_merge!(v.to_transport)
|
44
|
+
data_hash.deep_merge!(v.included_items_to_transport) if v.respond_to?(:included_items_to_transport)
|
45
|
+
elsif v.is_a?(Array)
|
46
|
+
v.each do |e|
|
47
|
+
if e
|
48
|
+
data_hash.deep_merge!(e.to_transport)
|
49
|
+
data_hash.deep_merge!(e.included_items_to_transport) if e.respond_to?(:included_items_to_transport)
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
@@ -99,6 +106,14 @@ module LucidObject
|
|
99
106
|
Isomorfeus.add_valid_data_class(base) unless base == LucidObject::Base
|
100
107
|
|
101
108
|
base.instance_exec do
|
109
|
+
def _instance_from_transport_sid(sid, included_items_data, _already_loaded)
|
110
|
+
o_class_name = sid[0]
|
111
|
+
raise "invalid data class #{o_class_name}" unless Isomorfeus.valid_data_class_name?(o_class_name)
|
112
|
+
o_class = Isomorfeus.cached_data_class(o_class_name)
|
113
|
+
o_data = { o_class_name => { sid[1] => included_items_data[o_class_name][sid[1]] }}
|
114
|
+
o_class.instance_from_transport(o_data, included_items_data, _already_loaded)
|
115
|
+
end
|
116
|
+
|
102
117
|
def instance_from_transport(instance_data, included_items_data, _already_loaded = {})
|
103
118
|
key = instance_data[self.name].keys.first
|
104
119
|
ref_s = gen_ref_s(key)
|
@@ -110,16 +125,15 @@ module LucidObject
|
|
110
125
|
if fields
|
111
126
|
field_types.each do |field, type|
|
112
127
|
if type == :object
|
113
|
-
|
114
|
-
if
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
128
|
+
sid_or_array = fields[field]
|
129
|
+
if sid_or_array&.any?
|
130
|
+
if sid_or_array[0].is_a? String
|
131
|
+
fields[field] = _instance_from_transport_sid(sid_or_array, included_items_data, _already_loaded)
|
132
|
+
elsif sid_or_array[0].is_a? Array
|
133
|
+
v = sid_or_array.map { |e_sid| _instance_from_transport_sid(e_sid, included_items_data, _already_loaded) }
|
134
|
+
v.compact!
|
135
|
+
fields[field] = v
|
121
136
|
end
|
122
|
-
fields[field] = o_class.instance_from_transport(o_data, included_items_data, _already_loaded)
|
123
137
|
end
|
124
138
|
end
|
125
139
|
end
|
@@ -141,10 +155,19 @@ module LucidObject
|
|
141
155
|
end
|
142
156
|
|
143
157
|
def each(&block)
|
144
|
-
|
145
|
-
|
158
|
+
if block_given?
|
159
|
+
self.object_accelerator.each do |fields|
|
160
|
+
block.call self.new(key: fields.delete(:key), fields: fields)
|
161
|
+
end
|
162
|
+
else
|
163
|
+
Enumerator.new do |yielder|
|
164
|
+
self.object_accelerator.each do |fields|
|
165
|
+
yielder << self.new(key: fields.delete(:key), fields: fields)
|
166
|
+
end
|
167
|
+
end
|
146
168
|
end
|
147
169
|
end
|
170
|
+
alias to_enum each
|
148
171
|
|
149
172
|
def search(field = nil, val = nil, options = {}, query: nil)
|
150
173
|
if field && !self.field_options[field]&.fetch(:index) == :yes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,28 +100,28 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.5.
|
103
|
+
version: 2.5.5
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.5.
|
110
|
+
version: 2.5.5
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: isomorfeus-policy
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - '='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.5.
|
117
|
+
version: 2.5.5
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - '='
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.5.
|
124
|
+
version: 2.5.5
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: isomorfeus-preact
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,28 +156,28 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - '='
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 2.5.
|
159
|
+
version: 2.5.5
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 2.5.
|
166
|
+
version: 2.5.5
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: isomorfeus
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - '='
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 2.5.
|
173
|
+
version: 2.5.5
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - '='
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 2.5.
|
180
|
+
version: 2.5.5
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rake
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|