isomorfeus-data 1.0.0.zeta25 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +47 -21
- data/README.md +38 -46
- data/lib/isomorfeus/data/attribute_support.rb +176 -176
- data/lib/isomorfeus/data/config.rb +79 -110
- data/lib/isomorfeus/data/element_validator.rb +147 -147
- data/lib/isomorfeus/data/ferret_accelerator.rb +66 -0
- data/lib/isomorfeus/data/field_support.rb +110 -0
- data/lib/isomorfeus/data/generic_class_api.rb +136 -116
- data/lib/isomorfeus/data/generic_instance_api.rb +150 -145
- data/lib/isomorfeus/data/hamster_accelerator.rb +87 -0
- data/lib/isomorfeus/data/hamster_storage_expander.rb +94 -0
- data/lib/isomorfeus/data/handler/generic.rb +134 -138
- data/lib/isomorfeus/data/reducer.rb +30 -30
- data/lib/isomorfeus/data/version.rb +4 -4
- data/lib/isomorfeus-data.rb +56 -64
- data/lib/isomorfeus_data/lucid_document/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_document/mixin.rb +148 -0
- data/lib/isomorfeus_data/lucid_file/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_file/mixin.rb +217 -0
- data/lib/isomorfeus_data/lucid_object/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_object/mixin.rb +216 -0
- data/lib/isomorfeus_data/lucid_query/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_query/mixin.rb +81 -0
- data/lib/isomorfeus_data/lucid_query_result.rb +97 -0
- data/opal/uri/common.rb +18 -0
- data/opal/uri/generic.rb +47 -0
- data/opal/uri.rb +29 -0
- metadata +85 -96
- data/lib/isomorfeus/data/handler/arango.rb +0 -56
- data/lib/isomorfeus/data/handler/object_call.rb +0 -40
- data/lib/isomorfeus/data/handler/object_store.rb +0 -40
- data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/array/mixin.rb +0 -580
- data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/collection/finders.rb +0 -83
- data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +0 -737
- data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +0 -234
- data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/document/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +0 -286
- data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +0 -134
- data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +0 -747
- data/lib/isomorfeus_data/lucid_data/generic_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_node.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/graph/finders.rb +0 -141
- data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +0 -489
- data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +0 -427
- data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/node/mixin.rb +0 -232
- data/lib/isomorfeus_data/lucid_data/query/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/query/mixin.rb +0 -83
- data/lib/isomorfeus_data/lucid_data/query_result.rb +0 -95
- data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +0 -9
- data/lib/lucid_arango/collection/base.rb +0 -13
- data/lib/lucid_arango/collection/mixin.rb +0 -18
- data/lib/lucid_arango/document/base.rb +0 -13
- data/lib/lucid_arango/document/mixin.rb +0 -9
- data/lib/lucid_arango/edge/base.rb +0 -13
- data/lib/lucid_arango/edge/mixin.rb +0 -18
- data/lib/lucid_arango/edge_collection/base.rb +0 -13
- data/lib/lucid_arango/edge_collection/mixin.rb +0 -18
- data/lib/lucid_arango/graph/base.rb +0 -13
- data/lib/lucid_arango/graph/mixin.rb +0 -18
- data/lib/lucid_arango/node/base.rb +0 -13
- data/lib/lucid_arango/node/mixin.rb +0 -79
- data/lib/lucid_arango/object/base.rb +0 -11
- data/lib/lucid_arango/object/mixin.rb +0 -158
- data/lib/lucid_arango/remote_object/base.rb +0 -11
- data/lib/lucid_arango/remote_object/mixin.rb +0 -17
- data/lib/lucid_arango/vertex/base.rb +0 -13
- data/lib/lucid_arango/vertex/mixin.rb +0 -9
@@ -1,737 +0,0 @@
|
|
1
|
-
module LucidData
|
2
|
-
module Collection
|
3
|
-
module Mixin
|
4
|
-
def self.included(base)
|
5
|
-
base.include(Enumerable)
|
6
|
-
base.include(Isomorfeus::Data::AttributeSupport)
|
7
|
-
base.extend(Isomorfeus::Data::GenericClassApi)
|
8
|
-
base.include(Isomorfeus::Data::GenericInstanceApi)
|
9
|
-
base.include(LucidData::Collection::Finders)
|
10
|
-
|
11
|
-
base.instance_exec do
|
12
|
-
def nodes(validate_hash)
|
13
|
-
@node_conditions = validate_hash
|
14
|
-
end
|
15
|
-
alias document nodes
|
16
|
-
alias vertices nodes
|
17
|
-
alias vertexes nodes
|
18
|
-
alias vertex nodes
|
19
|
-
alias documents nodes
|
20
|
-
alias node nodes
|
21
|
-
|
22
|
-
def node_conditions
|
23
|
-
@node_conditions ||= {}
|
24
|
-
end
|
25
|
-
|
26
|
-
def valid_node?(node)
|
27
|
-
return true unless node_conditions.any?
|
28
|
-
_validate_node(node)
|
29
|
-
rescue
|
30
|
-
false
|
31
|
-
end
|
32
|
-
alias valid_vertex? valid_node?
|
33
|
-
alias valid_document? valid_node?
|
34
|
-
|
35
|
-
def _validate_node(node)
|
36
|
-
Isomorfeus::Data::ElementValidator.new(self.to_s, node, node_conditions).validate!
|
37
|
-
end
|
38
|
-
|
39
|
-
def _validate_nodes(many_nodes)
|
40
|
-
many_nodes.each { |node| _validate_node(node) } if node_conditions.any?
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def _validate_node(node)
|
45
|
-
self.class._validate_node(node)
|
46
|
-
end
|
47
|
-
|
48
|
-
def _validate_nodes(many_nodes)
|
49
|
-
self.class._validate_nodes(many_nodes)
|
50
|
-
end
|
51
|
-
|
52
|
-
def _collection_to_sids(collection)
|
53
|
-
collection.map do |node|
|
54
|
-
node.respond_to?(:to_sid) ? node.to_sid : node
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def _node_sid_from_arg(arg)
|
59
|
-
if arg.respond_to?(:to_sid)
|
60
|
-
sid = arg.to_sid
|
61
|
-
node = arg
|
62
|
-
else
|
63
|
-
sid = arg
|
64
|
-
node = Isomorfeus.instance_from_sid(sid)
|
65
|
-
end
|
66
|
-
[node, sid]
|
67
|
-
end
|
68
|
-
|
69
|
-
def graph
|
70
|
-
@_graph
|
71
|
-
end
|
72
|
-
|
73
|
-
def graph=(g)
|
74
|
-
@_graph = g
|
75
|
-
end
|
76
|
-
|
77
|
-
def composition
|
78
|
-
@_composition
|
79
|
-
end
|
80
|
-
|
81
|
-
def composition=(c)
|
82
|
-
@_composition = c
|
83
|
-
end
|
84
|
-
|
85
|
-
def changed?
|
86
|
-
@_changed
|
87
|
-
end
|
88
|
-
|
89
|
-
def changed!
|
90
|
-
@_graph.changed! if @_graph
|
91
|
-
@_composition.changed! if @_composition
|
92
|
-
@_changed = true
|
93
|
-
end
|
94
|
-
|
95
|
-
def to_transport
|
96
|
-
hash = { 'attributes' => _get_selected_attributes, 'nodes' => nodes_as_sids }
|
97
|
-
hash.merge!('revision' => revision) if revision
|
98
|
-
result = { @class_name => { @key => hash }}
|
99
|
-
result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
|
100
|
-
result
|
101
|
-
end
|
102
|
-
|
103
|
-
def included_items_to_transport
|
104
|
-
hash = {}
|
105
|
-
nodes.each do |node|
|
106
|
-
hash.deep_merge!(node.to_transport)
|
107
|
-
end
|
108
|
-
hash
|
109
|
-
end
|
110
|
-
|
111
|
-
if RUBY_ENGINE == 'opal'
|
112
|
-
def initialize(key:, revision: nil, attributes: nil, documents: nil, vertices: nil, vertexes: nil, nodes: nil, graph: nil, composition: nil)
|
113
|
-
@key = key.to_s
|
114
|
-
@class_name = self.class.name
|
115
|
-
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
116
|
-
@_graph = graph
|
117
|
-
_update_paths
|
118
|
-
@_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
|
119
|
-
@_composition = composition
|
120
|
-
@_changed = false
|
121
|
-
@_changed_collection = nil
|
122
|
-
@_validate_nodes = self.class.node_conditions.any?
|
123
|
-
|
124
|
-
loaded = loaded?
|
125
|
-
|
126
|
-
if attributes
|
127
|
-
_validate_attributes(attributes)
|
128
|
-
if loaded
|
129
|
-
raw_attributes = Redux.fetch_by_path(*@_store_path)
|
130
|
-
if `raw_attributes === null`
|
131
|
-
@_changed_attributes = !attributes ? {} : attributes
|
132
|
-
elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
|
133
|
-
@_changed_attributes = attributes
|
134
|
-
end
|
135
|
-
else
|
136
|
-
@_changed_attributes = attributes
|
137
|
-
end
|
138
|
-
else
|
139
|
-
@_changed_attributes = {}
|
140
|
-
end
|
141
|
-
|
142
|
-
nodes = documents || nodes || vertices || vertexes
|
143
|
-
if nodes && loaded
|
144
|
-
_validate_nodes(nodes)
|
145
|
-
raw_nodes = _collection_to_sids(nodes)
|
146
|
-
raw_collection = Redux.fetch_by_path(*@_nodes_path)
|
147
|
-
if raw_collection != raw_nodes
|
148
|
-
@_changed_collection = raw_nodes
|
149
|
-
end
|
150
|
-
elsif !loaded
|
151
|
-
@_changed_collection = []
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def _load_from_store!
|
156
|
-
@_changed = false
|
157
|
-
@_changed_attributes = {}
|
158
|
-
@_changed_collection = nil
|
159
|
-
end
|
160
|
-
|
161
|
-
def _update_paths
|
162
|
-
@_store_path = [:data_state, @class_name, @key, :attributes]
|
163
|
-
@_nodes_path = [:data_state, @class_name, @key, :nodes]
|
164
|
-
end
|
165
|
-
|
166
|
-
def nodes
|
167
|
-
nodes_as_sids.map do |node_sid|
|
168
|
-
node = Isomorfeus.instance_from_sid(node_sid)
|
169
|
-
node.collection = self
|
170
|
-
node
|
171
|
-
end
|
172
|
-
end
|
173
|
-
alias vertices nodes
|
174
|
-
alias vertexes nodes
|
175
|
-
alias documents nodes
|
176
|
-
|
177
|
-
def nodes_as_sids
|
178
|
-
return @_changed_collection if @_changed_collection
|
179
|
-
collection = Redux.fetch_by_path(*@_nodes_path)
|
180
|
-
return collection if collection
|
181
|
-
[]
|
182
|
-
end
|
183
|
-
|
184
|
-
def node_from_sid(sid)
|
185
|
-
node_sids = nodes_as_sids
|
186
|
-
if node_sids.include?(sid)
|
187
|
-
node = Isomorfeus.instance_from_sid(sid)
|
188
|
-
node.collection = self
|
189
|
-
return node
|
190
|
-
end
|
191
|
-
nil
|
192
|
-
end
|
193
|
-
|
194
|
-
def each(&block)
|
195
|
-
nodes.each(&block)
|
196
|
-
end
|
197
|
-
|
198
|
-
def method_missing(method_name, *args, &block)
|
199
|
-
if method_name.JS.startsWith('find_by_')
|
200
|
-
attribute = method_name[8..-1] # remove 'find_by_'
|
201
|
-
value = args[0]
|
202
|
-
attribute_hash = { attribute => value }
|
203
|
-
attribute_hash.merge!(args[1]) if args[1]
|
204
|
-
find(attribute_hash)
|
205
|
-
else
|
206
|
-
collection = nodes
|
207
|
-
collection.send(method_name, *args, &block)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
def <<(node)
|
212
|
-
node, sid = _node_sid_from_arg(node)
|
213
|
-
_validate_node(node) if @_validate_nodes
|
214
|
-
raw_collection = nodes_as_sids
|
215
|
-
@_changed_collection = raw_collection << sid
|
216
|
-
changed!
|
217
|
-
self
|
218
|
-
end
|
219
|
-
|
220
|
-
def [](idx)
|
221
|
-
sid = nodes_as_sids[idx]
|
222
|
-
node = Isomorfeus.instance_from_sid(sid)
|
223
|
-
node.collection = self
|
224
|
-
node
|
225
|
-
end
|
226
|
-
|
227
|
-
def []=(idx, node)
|
228
|
-
node, sid = _node_sid_from_arg(node)
|
229
|
-
_validate_node(node) if @_validate_nodes
|
230
|
-
raw_collection = nodes_as_sids
|
231
|
-
raw_collection[idx] = sid
|
232
|
-
@_changed_collection = raw_collection
|
233
|
-
changed!
|
234
|
-
node
|
235
|
-
end
|
236
|
-
|
237
|
-
def clear
|
238
|
-
@_changed_collection = []
|
239
|
-
changed!
|
240
|
-
self
|
241
|
-
end
|
242
|
-
|
243
|
-
def collect!(&block)
|
244
|
-
collection = nodes
|
245
|
-
collection.collect!(&block)
|
246
|
-
@_changed_collection = _collection_to_sids(collection)
|
247
|
-
changed!
|
248
|
-
self
|
249
|
-
end
|
250
|
-
|
251
|
-
def compact!
|
252
|
-
raw_collection = nodes_as_sids
|
253
|
-
result = raw_collection.compact!
|
254
|
-
return nil if result.nil?
|
255
|
-
@_changed_collection = raw_collection
|
256
|
-
changed!
|
257
|
-
self
|
258
|
-
end
|
259
|
-
|
260
|
-
def concat(*args)
|
261
|
-
sids = args.map do |node|
|
262
|
-
node, sid = _node_sid_from_arg(node)
|
263
|
-
_validate_node(node)
|
264
|
-
sid
|
265
|
-
end
|
266
|
-
raw_collection = nodes_as_sids
|
267
|
-
raw_collection.concat(*sids)
|
268
|
-
@_changed_collection = raw_collection
|
269
|
-
changed!
|
270
|
-
self
|
271
|
-
end
|
272
|
-
|
273
|
-
def delete(node, &block)
|
274
|
-
node, sid = _node_sid_from_arg(node)
|
275
|
-
raw_collection = nodes_as_sids
|
276
|
-
result = raw_collection.delete(sid, &block)
|
277
|
-
return nil unless result
|
278
|
-
@_changed_collection = raw_collection
|
279
|
-
changed!
|
280
|
-
node
|
281
|
-
end
|
282
|
-
|
283
|
-
def delete_at(idx)
|
284
|
-
raw_collection = nodes_as_sids
|
285
|
-
result = raw_collection.delete_at(idx)
|
286
|
-
return nil if result.nil?
|
287
|
-
@_changed_collection = raw_collection
|
288
|
-
changed!
|
289
|
-
Isomorfeus.instance_from_sid(result)
|
290
|
-
end
|
291
|
-
|
292
|
-
def delete_if(&block)
|
293
|
-
collection = nodes
|
294
|
-
collection.delete_if(&block)
|
295
|
-
@_changed_collection = _collection_to_sids(collection)
|
296
|
-
changed!
|
297
|
-
self
|
298
|
-
end
|
299
|
-
|
300
|
-
def filter!(&block)
|
301
|
-
collection = nodes
|
302
|
-
result = collection.filter!(&block)
|
303
|
-
return nil if result.nil?
|
304
|
-
@_changed_collection = _collection_to_sids(collection)
|
305
|
-
changed!
|
306
|
-
self
|
307
|
-
end
|
308
|
-
|
309
|
-
def insert(index, *many_nodes)
|
310
|
-
sids = many_nodes.map do |node|
|
311
|
-
node, sid = _node_sid_from_arg(node)
|
312
|
-
_validate_node(node)
|
313
|
-
sid
|
314
|
-
end
|
315
|
-
raw_collection = nodes_as_sids
|
316
|
-
raw_collection.insert(index, sids)
|
317
|
-
@_changed_collection = raw_collection
|
318
|
-
changed!
|
319
|
-
self
|
320
|
-
end
|
321
|
-
|
322
|
-
def keep_if(&block)
|
323
|
-
collection = nodes
|
324
|
-
collection.keep_if(&block)
|
325
|
-
@_changed_collection = _collection_to_sids(collection)
|
326
|
-
changed!
|
327
|
-
self
|
328
|
-
end
|
329
|
-
|
330
|
-
def map!(&block)
|
331
|
-
collection = nodes
|
332
|
-
collection.map!(&block)
|
333
|
-
@_changed_collection = _collection_to_sids(collection)
|
334
|
-
changed!
|
335
|
-
self
|
336
|
-
end
|
337
|
-
|
338
|
-
def pop(n = nil)
|
339
|
-
raw_collection = nodes_as_sids
|
340
|
-
result = raw_collection.pop(n)
|
341
|
-
@_changed_collection = raw_collection
|
342
|
-
changed!
|
343
|
-
Isomorfeus.instance_from_sid(result)
|
344
|
-
end
|
345
|
-
|
346
|
-
def push(*many_nodes)
|
347
|
-
sids = many_nodes.map do |node|
|
348
|
-
node, sid = _node_sid_from_arg(node)
|
349
|
-
_validate_node(node)
|
350
|
-
sid
|
351
|
-
end
|
352
|
-
raw_collection = nodes_as_sids
|
353
|
-
raw_collection.push(*sids)
|
354
|
-
@_changed_collection = raw_collection
|
355
|
-
changed!
|
356
|
-
self
|
357
|
-
end
|
358
|
-
alias append push
|
359
|
-
|
360
|
-
def reject!(&block)
|
361
|
-
collection = nodes
|
362
|
-
result = collection.reject!(&block)
|
363
|
-
return nil if result.nil?
|
364
|
-
@_changed_collection = _collection_to_sids(collection)
|
365
|
-
changed!
|
366
|
-
self
|
367
|
-
end
|
368
|
-
|
369
|
-
def reverse!
|
370
|
-
raw_collection = nodes_as_sids
|
371
|
-
raw_collection.reverse!
|
372
|
-
@_changed_collection = raw_collection
|
373
|
-
changed!
|
374
|
-
self
|
375
|
-
end
|
376
|
-
|
377
|
-
def rotate!(count = 1)
|
378
|
-
raw_collection = nodes_as_sids
|
379
|
-
raw_collection.rotate!(count)
|
380
|
-
@_changed_collection = raw_collection
|
381
|
-
changed!
|
382
|
-
self
|
383
|
-
end
|
384
|
-
|
385
|
-
def select!(&block)
|
386
|
-
collection = nodes
|
387
|
-
result = collection.select!(&block)
|
388
|
-
return nil if result.nil?
|
389
|
-
@_changed_collection = _collection_to_sids(collection)
|
390
|
-
changed!
|
391
|
-
self
|
392
|
-
end
|
393
|
-
|
394
|
-
def shift(n = nil)
|
395
|
-
raw_collection = nodes_as_sids
|
396
|
-
result = raw_collection.shift(n)
|
397
|
-
@_changed_collection = raw_collection
|
398
|
-
changed!
|
399
|
-
Isomorfeus.instance_from_sid(result)
|
400
|
-
end
|
401
|
-
|
402
|
-
def shuffle!(*args)
|
403
|
-
raw_collection = nodes_as_sids
|
404
|
-
raw_collection.shuffle!(*args)
|
405
|
-
@_changed_collection = raw_collection
|
406
|
-
changed!
|
407
|
-
self
|
408
|
-
end
|
409
|
-
|
410
|
-
def slice!(*args)
|
411
|
-
raw_collection = nodes_as_sids
|
412
|
-
result = raw_collection.slice!(*args)
|
413
|
-
@_changed_collection = raw_collection
|
414
|
-
changed!
|
415
|
-
return nil if result.nil?
|
416
|
-
# TODO
|
417
|
-
result
|
418
|
-
end
|
419
|
-
|
420
|
-
def sort!(&block)
|
421
|
-
collection = nodes
|
422
|
-
collection.sort!(&block)
|
423
|
-
@_changed_collection = _collection_to_sids(collection)
|
424
|
-
changed!
|
425
|
-
self
|
426
|
-
end
|
427
|
-
|
428
|
-
def sort_by!(&block)
|
429
|
-
collection = nodes
|
430
|
-
collection.sort_by!(&block)
|
431
|
-
@_changed_collection = _collection_to_sids(collection)
|
432
|
-
changed!
|
433
|
-
self
|
434
|
-
end
|
435
|
-
|
436
|
-
def uniq!(&block)
|
437
|
-
collection = nodes
|
438
|
-
collection.uniq!(&block)
|
439
|
-
@_changed_collection = _collection_to_sids(collection)
|
440
|
-
changed!
|
441
|
-
self
|
442
|
-
end
|
443
|
-
|
444
|
-
def unshift(*many_nodes)
|
445
|
-
sids = many_nodes.map do |node|
|
446
|
-
node, sid = _node_sid_from_arg(node)
|
447
|
-
_validate_node(node)
|
448
|
-
sid
|
449
|
-
end
|
450
|
-
raw_collection = nodes_as_sids
|
451
|
-
raw_collection.unshift(*sids)
|
452
|
-
@_changed_collection = raw_collection
|
453
|
-
changed!
|
454
|
-
self
|
455
|
-
end
|
456
|
-
alias prepend unshift
|
457
|
-
else # RUBY_ENGINE
|
458
|
-
Isomorfeus.add_valid_data_class(base) unless base == LucidData::Collection::Base
|
459
|
-
|
460
|
-
base.instance_exec do
|
461
|
-
def instance_from_transport(instance_data, included_items_data)
|
462
|
-
key = instance_data[self.name].keys.first
|
463
|
-
revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
|
464
|
-
attributes = instance_data[self.name][key].key?('attributes') ? instance_data[self.name][key]['attributes'].transform_keys!(&:to_sym) : nil
|
465
|
-
nodes_sids = instance_data[self.name][key].key?('nodes') ? instance_data[self.name][key]['nodes'] : []
|
466
|
-
nodes = []
|
467
|
-
nodes_sids.each do |sid|
|
468
|
-
node_class_name = sid[0]
|
469
|
-
node_key = sid[1]
|
470
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Not a valid LucidData class!") unless Isomorfeus.valid_data_class_name?(node_class_name)
|
471
|
-
if included_items_data.key?(node_class_name) && included_items_data[node_class_name].key?(node_key)
|
472
|
-
node_class = Isomorfeus.cached_data_class(node_class_name)
|
473
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Cannot get class!") unless node_class
|
474
|
-
node = node_class.instance_from_transport({ node_class_name => { node_key => included_items_data[node_class_name][node_key] }}, included_items_data)
|
475
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name} with key #{node_key} could not be extracted from transport data!") unless node
|
476
|
-
nodes << node
|
477
|
-
end
|
478
|
-
end
|
479
|
-
new(key: key, revision: revision, attributes: attributes, nodes: nodes)
|
480
|
-
end
|
481
|
-
end
|
482
|
-
|
483
|
-
def initialize(key:, revision: nil, attributes: nil, documents: nil, vertexes: nil, vertices: nil, nodes: nil, graph: nil, composition: nil)
|
484
|
-
@key = key.to_s
|
485
|
-
@class_name = self.class.name
|
486
|
-
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
487
|
-
@_revision = revision
|
488
|
-
@_graph = graph
|
489
|
-
@_composition = composition
|
490
|
-
@_changed = false
|
491
|
-
@_validate_attributes = self.class.attribute_conditions.any?
|
492
|
-
@_validate_nodes = self.class.node_conditions.any?
|
493
|
-
|
494
|
-
attributes = {} unless attributes
|
495
|
-
_validate_attributes(attributes) if attributes
|
496
|
-
@_raw_attributes = attributes
|
497
|
-
|
498
|
-
nodes = documents || nodes || vertices || vertexes
|
499
|
-
nodes = [] unless nodes
|
500
|
-
_validate_nodes(nodes) if @_validate_nodes
|
501
|
-
nodes.each { |n| n.collection = self }
|
502
|
-
@_raw_collection = nodes
|
503
|
-
@_sid_to_node_cache = {}
|
504
|
-
end
|
505
|
-
|
506
|
-
def _unchange!
|
507
|
-
@_changed = false
|
508
|
-
end
|
509
|
-
|
510
|
-
def nodes
|
511
|
-
@_raw_collection
|
512
|
-
end
|
513
|
-
alias vertices nodes
|
514
|
-
alias vertexes nodes
|
515
|
-
alias documents nodes
|
516
|
-
|
517
|
-
def nodes_as_sids
|
518
|
-
@_raw_collection.map(&:to_sid)
|
519
|
-
end
|
520
|
-
|
521
|
-
def node_from_sid(sid)
|
522
|
-
return @_sid_to_node_cache[sid] if @_sid_to_node_cache.key?(sid)
|
523
|
-
node = nil
|
524
|
-
idx = @_raw_collection.find_index { |node| node.to_sid == sid }
|
525
|
-
node = @_raw_collection[idx] if idx
|
526
|
-
@_sid_to_node_cache[sid] = node
|
527
|
-
end
|
528
|
-
|
529
|
-
def each(&block)
|
530
|
-
@_raw_collection.each(&block)
|
531
|
-
end
|
532
|
-
|
533
|
-
def method_missing(method_name, *args, &block)
|
534
|
-
method_name_s = method_name.to_s
|
535
|
-
if method_name_s.start_with?('find_by_')
|
536
|
-
attribute = method_name_s[8..-1] # remove 'find_by_'
|
537
|
-
value = args[0]
|
538
|
-
attribute_hash = { attribute => value }
|
539
|
-
attribute_hash.merge!(args[1]) if args[1]
|
540
|
-
find(attribute_hash)
|
541
|
-
else
|
542
|
-
@_raw_collection.send(method_name, *args, &block)
|
543
|
-
end
|
544
|
-
end
|
545
|
-
|
546
|
-
def <<(node)
|
547
|
-
_validate_node(node) if @_validate_nodes
|
548
|
-
changed!
|
549
|
-
@_raw_collection << node
|
550
|
-
node
|
551
|
-
end
|
552
|
-
|
553
|
-
def []=(idx, node)
|
554
|
-
_validate_node(node) if @_validate_nodes
|
555
|
-
changed!
|
556
|
-
@_raw_collection[idx] = node
|
557
|
-
end
|
558
|
-
|
559
|
-
def clear
|
560
|
-
changed!
|
561
|
-
@_raw_collection = []
|
562
|
-
self
|
563
|
-
end
|
564
|
-
|
565
|
-
def collect!(&block)
|
566
|
-
changed!
|
567
|
-
@_raw_collection.collect!(&block)
|
568
|
-
self
|
569
|
-
end
|
570
|
-
|
571
|
-
def compact!
|
572
|
-
@_raw_collection.compact!
|
573
|
-
return nil if result.nil?
|
574
|
-
changed!
|
575
|
-
self
|
576
|
-
end
|
577
|
-
|
578
|
-
def concat(*many_nodes)
|
579
|
-
if @_validate_nodes
|
580
|
-
many_nodes = many_nodes.map do |node|
|
581
|
-
_validate_node(node)
|
582
|
-
node
|
583
|
-
end
|
584
|
-
end
|
585
|
-
changed!
|
586
|
-
@_raw_collection.concat(*many_nodes)
|
587
|
-
self
|
588
|
-
end
|
589
|
-
|
590
|
-
def delete(node, &block)
|
591
|
-
result = @_raw_collection.delete(node, &block)
|
592
|
-
changed!
|
593
|
-
result
|
594
|
-
end
|
595
|
-
|
596
|
-
def delete_at(idx)
|
597
|
-
result = @_raw_collection.delete_at(idx)
|
598
|
-
return nil if result.nil?
|
599
|
-
changed!
|
600
|
-
result
|
601
|
-
end
|
602
|
-
|
603
|
-
def delete_if(&block)
|
604
|
-
@_raw_collection.delete_if(&block)
|
605
|
-
changed!
|
606
|
-
self
|
607
|
-
end
|
608
|
-
|
609
|
-
def filter!(&block)
|
610
|
-
result = @_raw_collection.filter!(&block)
|
611
|
-
return nil if result.nil?
|
612
|
-
changed!
|
613
|
-
self
|
614
|
-
end
|
615
|
-
|
616
|
-
def insert(idx, *many_nodes)
|
617
|
-
if @_validate_nodes
|
618
|
-
many_nodes = many_nodes.map do |node|
|
619
|
-
_validate_node(node)
|
620
|
-
node
|
621
|
-
end
|
622
|
-
end
|
623
|
-
@_raw_collection.insert(idx, *many_nodes)
|
624
|
-
changed!
|
625
|
-
self
|
626
|
-
end
|
627
|
-
|
628
|
-
def keep_if(&block)
|
629
|
-
@_raw_collection.keep_if(&block)
|
630
|
-
changed!
|
631
|
-
self
|
632
|
-
end
|
633
|
-
|
634
|
-
def map!(&block)
|
635
|
-
@_raw_collection.map!(&block)
|
636
|
-
changed!
|
637
|
-
self
|
638
|
-
end
|
639
|
-
|
640
|
-
def pop(n = nil)
|
641
|
-
result = @_raw_collection.pop(n)
|
642
|
-
changed!
|
643
|
-
result
|
644
|
-
end
|
645
|
-
|
646
|
-
def push(*many_nodes)
|
647
|
-
if @_validate_nodes
|
648
|
-
many_nodes = many_nodes.map do |node|
|
649
|
-
_validate_node(node)
|
650
|
-
node
|
651
|
-
end
|
652
|
-
end
|
653
|
-
@_raw_collection.push(*many_nodes)
|
654
|
-
changed!
|
655
|
-
self
|
656
|
-
end
|
657
|
-
alias append push
|
658
|
-
|
659
|
-
def reject!(&block)
|
660
|
-
result = @_raw_collection.reject!(&block)
|
661
|
-
return nil if result.nil?
|
662
|
-
changed!
|
663
|
-
self
|
664
|
-
end
|
665
|
-
|
666
|
-
def reverse!
|
667
|
-
@_raw_collection.reverse!
|
668
|
-
changed!
|
669
|
-
self
|
670
|
-
end
|
671
|
-
|
672
|
-
def rotate!(count = 1)
|
673
|
-
@_raw_collection.rotate!(count)
|
674
|
-
changed!
|
675
|
-
self
|
676
|
-
end
|
677
|
-
|
678
|
-
def select!(&block)
|
679
|
-
result = @_raw_collection.select!(&block)
|
680
|
-
return nil if result.nil?
|
681
|
-
changed!
|
682
|
-
self
|
683
|
-
end
|
684
|
-
|
685
|
-
def shift(n = nil)
|
686
|
-
result = @_raw_collection.shift(n)
|
687
|
-
changed!
|
688
|
-
result
|
689
|
-
end
|
690
|
-
|
691
|
-
def shuffle!(*args)
|
692
|
-
@_raw_collection.shuffle!(*args)
|
693
|
-
changed!
|
694
|
-
self
|
695
|
-
end
|
696
|
-
|
697
|
-
def slice!(*args)
|
698
|
-
result = @_raw_collection.slice!(*args)
|
699
|
-
changed!
|
700
|
-
result
|
701
|
-
end
|
702
|
-
|
703
|
-
def sort!(&block)
|
704
|
-
@_raw_collection.sort!(&block)
|
705
|
-
changed!
|
706
|
-
self
|
707
|
-
end
|
708
|
-
|
709
|
-
def sort_by!(&block)
|
710
|
-
@_raw_collection.sort_by!(&block)
|
711
|
-
changed!
|
712
|
-
self
|
713
|
-
end
|
714
|
-
|
715
|
-
def uniq!(&block)
|
716
|
-
@_raw_collection.uniq!(&block)
|
717
|
-
changed!
|
718
|
-
self
|
719
|
-
end
|
720
|
-
|
721
|
-
def unshift(*many_nodes)
|
722
|
-
if @_validate_nodes
|
723
|
-
many_nodes = many_nodes.map do |node|
|
724
|
-
_validate_node(node)
|
725
|
-
node
|
726
|
-
end
|
727
|
-
end
|
728
|
-
@_raw_collection.unshift(*many_nodes)
|
729
|
-
changed!
|
730
|
-
self
|
731
|
-
end
|
732
|
-
alias prepend unshift
|
733
|
-
end # RUBY_ENGINE
|
734
|
-
end
|
735
|
-
end
|
736
|
-
end
|
737
|
-
end
|