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