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