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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -1
  3. data/lib/isomorfeus/data/attribute_support.rb +122 -0
  4. data/lib/isomorfeus/data/config.rb +79 -89
  5. data/lib/isomorfeus/data/element_validator.rb +133 -0
  6. data/lib/isomorfeus/data/generic_class_api.rb +155 -0
  7. data/lib/isomorfeus/data/generic_instance_api.rb +72 -0
  8. data/lib/isomorfeus/data/handler/arango.rb +61 -0
  9. data/lib/isomorfeus/data/handler/generic.rb +92 -0
  10. data/lib/isomorfeus/data/handler/object_call.rb +45 -0
  11. data/lib/isomorfeus/data/handler/object_store.rb +45 -0
  12. data/lib/isomorfeus/data/version.rb +1 -1
  13. data/lib/isomorfeus-data.rb +61 -30
  14. data/lib/isomorfeus_data/lucid_data/array/base.rb +15 -0
  15. data/lib/isomorfeus_data/lucid_data/array/mixin.rb +570 -0
  16. data/lib/isomorfeus_data/lucid_data/collection/base.rb +15 -0
  17. data/lib/isomorfeus_data/lucid_data/collection/finders.rb +83 -0
  18. data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +710 -0
  19. data/lib/isomorfeus_data/lucid_data/composition/base.rb +15 -0
  20. data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +185 -0
  21. data/lib/isomorfeus_data/lucid_data/document/base.rb +15 -0
  22. data/lib/isomorfeus_data/lucid_data/document/mixin.rb +9 -0
  23. data/lib/isomorfeus_data/lucid_data/edge/base.rb +15 -0
  24. data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +281 -0
  25. data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +15 -0
  26. data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +134 -0
  27. data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +705 -0
  28. data/lib/isomorfeus_data/lucid_data/graph/base.rb +15 -0
  29. data/lib/isomorfeus_data/lucid_data/graph/finders.rb +141 -0
  30. data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +401 -0
  31. data/lib/isomorfeus_data/lucid_data/hash/base.rb +15 -0
  32. data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +413 -0
  33. data/lib/isomorfeus_data/lucid_data/link/base.rb +15 -0
  34. data/lib/isomorfeus_data/lucid_data/link/mixin.rb +9 -0
  35. data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +15 -0
  36. data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +9 -0
  37. data/lib/isomorfeus_data/lucid_data/node/base.rb +15 -0
  38. data/lib/isomorfeus_data/lucid_data/node/mixin.rb +192 -0
  39. data/lib/isomorfeus_data/lucid_data/object/base.rb +13 -0
  40. data/lib/{lucid_array → isomorfeus_data/lucid_data/object}/mixin.rb +15 -16
  41. data/lib/isomorfeus_data/lucid_data/remote_object/base.rb +13 -0
  42. data/lib/isomorfeus_data/lucid_data/remote_object/mixin.rb +19 -0
  43. data/lib/isomorfeus_data/lucid_data/vertex/base.rb +15 -0
  44. data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +9 -0
  45. data/lib/lucid_arango/collection/base.rb +15 -0
  46. data/lib/lucid_arango/collection/mixin.rb +20 -0
  47. data/lib/lucid_arango/document/base.rb +15 -0
  48. data/lib/lucid_arango/document/mixin.rb +9 -0
  49. data/lib/lucid_arango/edge/base.rb +16 -0
  50. data/lib/lucid_arango/edge/mixin.rb +20 -0
  51. data/lib/lucid_arango/edge_collection/base.rb +15 -0
  52. data/lib/lucid_arango/edge_collection/mixin.rb +20 -0
  53. data/lib/lucid_arango/graph/base.rb +15 -0
  54. data/lib/lucid_arango/graph/mixin.rb +20 -0
  55. data/lib/lucid_arango/node/base.rb +16 -0
  56. data/lib/lucid_arango/node/mixin.rb +81 -0
  57. data/lib/lucid_arango/vertex/base.rb +15 -0
  58. data/lib/lucid_arango/vertex/mixin.rb +9 -0
  59. metadata +84 -47
  60. data/lib/isomorfeus/data/handler/array_load_handler.rb +0 -47
  61. data/lib/isomorfeus/data/handler/collection_load_handler.rb +0 -48
  62. data/lib/isomorfeus/data/handler/graph_load_handler.rb +0 -48
  63. data/lib/isomorfeus/data/handler/hash_load_handler.rb +0 -47
  64. data/lib/lucid_array/base.rb +0 -14
  65. data/lib/lucid_collection/base.rb +0 -14
  66. data/lib/lucid_collection/mixin.rb +0 -241
  67. data/lib/lucid_edge/base.rb +0 -5
  68. data/lib/lucid_edge/mixin.rb +0 -238
  69. data/lib/lucid_graph/base.rb +0 -14
  70. data/lib/lucid_graph/mixin.rb +0 -670
  71. data/lib/lucid_hash/base.rb +0 -14
  72. data/lib/lucid_hash/mixin.rb +0 -168
  73. data/lib/lucid_node/base.rb +0 -5
  74. data/lib/lucid_node/mixin.rb +0 -198
@@ -1,670 +0,0 @@
1
- module LucidGraph
2
- module Mixin
3
- def self.included(base)
4
- if RUBY_ENGINE != 'opal'
5
- Isomorfeus.add_valid_graph_class(base) unless base == LucidGraph::Base
6
- end
7
-
8
- base.extend(LucidPropDeclaration::Mixin)
9
-
10
- def find_edge(attribute_hash = nil, &block)
11
- if block_given?
12
- edges.each do |edge|
13
- return edge if block.call(edge)
14
- end
15
- else
16
- edge_class = attribute_hash.delete(:class)
17
- is_a_module = attribute_hash.delete(:is_a)
18
- edges.each do |edge|
19
- if edge_class
20
- next unless edge.class == edge_class
21
- end
22
- if is_a_module
23
- next unless edge.is_a?(is_a_module)
24
- end
25
- found = true
26
- attribute_hash.each do |k,v|
27
- found &&= (node[k] == v)
28
- break unless found
29
- end
30
- return edge if found
31
- end
32
- end
33
- nil
34
- end
35
-
36
- def find_edges(attribute_hash = nil, &block)
37
- found_edges = Set.new
38
- if block_given?
39
- edges.each do |edge|
40
- found_edges << edge if block.call(edge)
41
- end
42
- else
43
- edge_class = attribute_hash.delete(:class)
44
- is_a_module = attribute_hash.delete(:is_a)
45
- edges.each do |edge|
46
- if edge_class
47
- next unless edge.class == edge_class
48
- end
49
- if is_a_module
50
- next unless edge.is_a?(is_a_module)
51
- end
52
- found = true
53
- attribute_hash.each do |k,v|
54
- found &&= (node[k] == v)
55
- break unless found
56
- end
57
- found_edges << edge if found
58
- end
59
- end
60
- found_edges
61
- end
62
-
63
- def find_node(attribute_hash = nil, &block)
64
- if block_given?
65
- nodes.each do |node|
66
- return node if block.call(node)
67
- end
68
- else
69
- node_class = attribute_hash.delete(:class)
70
- is_a_module = attribute_hash.delete(:is_a)
71
- nodes.each do |node|
72
- if node_class
73
- next unless node.class == node_class
74
- end
75
- if is_a_module
76
- next unless node.is_a?(is_a_module)
77
- end
78
- found = true
79
- attribute_hash.each do |k,v|
80
- found &&= (node[k] == v)
81
- break unless found
82
- end
83
- return node if found
84
- end
85
- end
86
- nil
87
- end
88
-
89
- def find_nodes(attribute_hash = nil, &block)
90
- found_nodes = Set.new
91
- if block_given?
92
- nodes.each do |node|
93
- found_nodes << node if block.call(node)
94
- end
95
- else
96
- node_class = attribute_hash.delete(:class)
97
- is_a_module = attribute_hash.delete(:is_a)
98
- nodes.each do |node|
99
- if node_class
100
- next unless node.class == node_class
101
- end
102
- if is_a_module
103
- next unless node.is_a?(is_a_module)
104
- end
105
- found = true
106
- attribute_hash.each do |k,v|
107
- found &&= (node[k] == v)
108
- break unless found
109
- end
110
- found_nodes << node if found
111
- end
112
- end
113
- found_nodes
114
- end
115
-
116
- def to_gid
117
- [@class_name, @props_json]
118
- end
119
-
120
- def to_transport(inline: false)
121
- items_hash = {}
122
- own_edge_cids = own_edges_as_cids
123
- own_node_cids = own_nodes_as_cids
124
- items_hash['edges'] = own_edge_cids.to_a if own_edge_cids.size > 0
125
- items_hash['nodes'] = own_node_cids.to_a if own_node_cids.size > 0
126
-
127
- if @included_arrays.size > 0
128
- items_hash['included_arrays'] = {}
129
- @included_arrays.each do |name, instance|
130
- items_hash['included_arrays'][name.to_s] = if self.class.included_arrays[name].key?(:anonymous)
131
- instance.to_transport(inline: true)
132
- else
133
- instance.to_gid
134
- end
135
- end
136
- end
137
-
138
- if @included_collections.size > 0
139
- items_hash['included_collections'] = {}
140
- @included_collections.each do |name, instance|
141
- items_hash['included_collections'][name.to_s] = if self.class.included_collections[name].key?(:anonymous)
142
- instance.to_transport(inline: true)
143
- else
144
- instance.to_gid
145
- end
146
- end
147
- end
148
-
149
- if @included_graphs.size > 0
150
- items_hash['included_graphs'] = {}
151
- @included_graphs.each do |name, instance|
152
- items_hash['included_graphs'][name.to_s] = if self.class.included_graphs[name].key?(:anonymous)
153
- instance.to_transport(inline: true)
154
- else
155
- instance.to_gid
156
- end
157
- end
158
- end
159
-
160
- if @included_hashes.size > 0
161
- items_hash['included_hashes'] = {}
162
- @included_hashes.each do |name, instance|
163
- items_hash['included_hashes'][name.to_s] = if self.class.included_hashes[name].key?(:anonymous)
164
- instance.to_transport(inline: true)
165
- else
166
- instance.to_gid
167
- end
168
- end
169
- end
170
-
171
- incl_nodes = included_nodes
172
- if incl_nodes.size > 0
173
- items_hash['included_nodes'] = {}
174
- incl_nodes.each do |name, instance|
175
- items_hash['included_nodes'][name.to_s] = instance.to_cid
176
- end
177
- end
178
-
179
- if inline
180
- { '_inline' => { @props_json => items_hash }}
181
- else
182
- { 'graphs' => { @class_name => { @props_json => items_hash }}}
183
- end
184
- end
185
-
186
- def included_items_to_transport
187
- result_hash = {}
188
-
189
- self.class.included_arrays.each do |name, options|
190
- unless options.key?(:anonymous)
191
- result_hash.deep_merge!(@included_arrays[name].to_transport)
192
- end
193
- end
194
-
195
- self.class.included_collections.each do |name, options|
196
- unless options.key?(:anonymous)
197
- result_hash.deep_merge!(@included_collections[name].to_transport)
198
- end
199
- result_hash.deep_merge!(@included_collections[name].included_items_to_transport)
200
- end
201
-
202
- self.class.included_graphs.each do |name, options|
203
- unless options.key?(:anonymous)
204
- result_hash.deep_merge!(@included_graphs[name].to_transport)
205
- end
206
- result_hash.deep_merge!(@included_graphs[name].included_items_to_transport)
207
- end
208
-
209
- self.class.included_hashes.each do |name, options|
210
- unless options.key?(:anonymous)
211
- result_hash.deep_merge!(@included_hashes[name].to_transport)
212
- end
213
- end
214
-
215
- included_nodes.each_value do |instance|
216
- result_hash.deep_merge!(instance.to_transport)
217
- end
218
-
219
- edges.each do |edge|
220
- result_hash.deep_merge!(edge.to_transport)
221
- end
222
-
223
- nodes.each do |node|
224
- result_hash.deep_merge!(node.to_transport)
225
- end
226
-
227
- result_hash
228
- end
229
-
230
- base.instance_exec do
231
- def included_arrays
232
- @included_arrays ||= {}
233
- end
234
-
235
- def included_collections
236
- @included_collections ||= {}
237
- end
238
-
239
- def included_graphs
240
- @included_graphs ||= {}
241
- end
242
-
243
- def included_hashes
244
- @included_hashes ||= {}
245
- end
246
-
247
- def included_nodes
248
- @included_nodes ||= {}
249
- end
250
-
251
- def on_load_block
252
- @on_load_block
253
- end
254
-
255
- def query_block
256
- @query_block
257
- end
258
- end
259
-
260
- if RUBY_ENGINE == 'opal'
261
- def initialize(store_path: nil, validated_props: nil)
262
- @props = validated_props
263
- @props_json = @props.to_json if @props
264
- @class_name = self.class.name
265
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
266
- @store_path = store_path ? store_path : [:data_state, :graphs, @class_name, @props_json]
267
-
268
- @included_arrays = {}
269
- self.class.included_arrays.each do |name, options|
270
- @included_arrays[name] = if options.key?(:anonymous)
271
- options[:class].new(store_path: @store_path + [:included_arrays, name, :_inline],
272
- validated_props: @props)
273
- else
274
- options[:class].new(validated_props: @props)
275
- end
276
- end
277
- @included_collections = {}
278
- self.class.included_collections.each do |name, options|
279
- @included_collections[name] = if options.key?(:anonymous)
280
- options[:class].new(store_path: @store_path + [:included_arrays, name, :_inline],
281
- validated_props: @props)
282
- else
283
- options[:class].new(validated_props: @props)
284
- end
285
- end
286
- @included_graphs = {}
287
- self.class.included_graphs.each do |name, options|
288
- @included_graphs[name] = if options.key?(:anonymous)
289
- options[:class].new(store_path: @store_path + [:included_arrays, name, :_inline],
290
- validated_props: @props)
291
- else
292
- options[:class].new(validated_props: @props)
293
- end
294
- end
295
- @included_hashes = {}
296
- self.class.included_hashes.each do |name, options|
297
- @included_hashes[name] = if options.key?(:anonymous)
298
- options[:class].new(store_path: @store_path + [:included_arrays, name, :_inline],
299
- validated_props: @props)
300
- else
301
- options[:class].new(validated_props: @props)
302
- end
303
- end
304
- end
305
-
306
- def loaded?
307
- Redux.fetch_by_path(*@store_path) ? true : false
308
- end
309
-
310
- def edges
311
- edges_as_cids.map { |edge_cid| LucidEdge::Base.edge_from_cid(edge_cid) }
312
- end
313
-
314
- def edges_as_cids
315
- edge_cids = own_edges_as_cids
316
- @included_graphs.each_value { |graph| edge_cids += graph.edges_as_cids }
317
- edge_cids
318
- end
319
-
320
- def own_edges_as_cids
321
- path = @store_path + [:edges]
322
- edge_cids = Redux.fetch_by_path(*path)
323
- edge_cids ? Set.new(edge_cids) : Set.new
324
- end
325
-
326
- def find_edge_by_id(edge_id)
327
- edges_as_cids.each do |edge_cid|
328
- return LucidNode::Base.edge_from_cid(edge_cid) if edge_cid[1] == edge_id
329
- end
330
- nil
331
- end
332
-
333
- def find_node_by_id(node_id)
334
- nodes_as_cids.each do |node_cid|
335
- return LucidNode::Base.node_from_cid(node_cid) if node_cid[1] == node_id
336
- end
337
- nil
338
- end
339
-
340
- def included_nodes
341
- incl_nodes = {}
342
- path = @store_path + [:included_nodes]
343
- self.class.included_nodes.each_key do |name|
344
- node_cid = Redux.fetch_by_path(*(path + [name]))
345
- incl_nodes[name] = LucidNode::Base.node_from_cid(node_cid) if node_cid
346
- end
347
- incl_nodes
348
- end
349
-
350
- def nodes
351
- nodes_as_cids.map { |node_cid| LucidNode::Base.node_from_cid(node_cid) }
352
- end
353
-
354
- def nodes_as_cids
355
- node_cids = own_nodes_as_cids
356
- @included_graphs.each_value { |graph| node_cids += graph.nodes_as_cids }
357
- @included_collections.each_value { |collection| node_cids += collection.nodes_as_cids }
358
- included_nodes.each_value { |node| node_cids << node.to_cid }
359
- node_cids
360
- end
361
-
362
- def own_nodes_as_cids
363
- path = @store_path + [:nodes]
364
- node_cids = Redux.fetch_by_path(*path)
365
- node_cids ? Set.new(node_cids) : Set.new
366
- end
367
-
368
- def method_missing(method_name, *args, &block)
369
- if method_name.JS.startsWith('find_node_by_')
370
- attribute = method_name[13..-1] # remove 'find_node_by_'
371
- value = args[0]
372
- attribute_hash = { attribute => value }
373
- attribute_hash.merge!(args[1]) if args[1]
374
- find_node(attribute_hash)
375
- elsif method_name.JS.startsWith('find_edge_by_')
376
- attribute = method_name[13..-1] # remove 'find_edge_by_'
377
- value = args[0]
378
- attribute_hash = { attribute => value }
379
- attribute_hash.merge!(args[1]) if args[1]
380
- find_edge(attribute_hash)
381
- else
382
- super
383
- end
384
- end
385
-
386
- base.instance_exec do
387
- def include_array(name, array_class = nil, &block)
388
- included_arrays[name] = if array_class
389
- { class: array_class }
390
- else
391
- new_class = Class.new(LucidArray::Base)
392
- new_class.instance_exec(&block)
393
- { anonymous: true, class: new_class }
394
- end
395
- define_method(name) do
396
- @included_arrays[name]
397
- end
398
- end
399
-
400
- def include_collection(name, collection_class = nil, &block)
401
- included_collections[name] = if collection_class
402
- { class: collection_class }
403
- else
404
- new_class = Class.new(LucidCollection::Base)
405
- new_class.instance_exec(&block)
406
- { anonymous: true, class: new_class }
407
- end
408
- define_method(name) do
409
- @included_collections[name]
410
- end
411
- end
412
-
413
- def include_graph(name, graph_class = nil, &block)
414
- included_graphs[name] = if graph_class
415
- { class: graph_class }
416
- else
417
- new_class = Class.new(LucidGraph::Base)
418
- new_class.instance_exec(&block)
419
- { anonymous: true, class: new_class }
420
- end
421
- define_method(name) do
422
- @included_graphs[name]
423
- end
424
- end
425
-
426
- def include_hash(name, hash_class = nil, &block)
427
- included_hashes[name] = if hash_class
428
- { class: hash_class }
429
- else
430
- new_class = Class.new(LucidHash::Base)
431
- new_class.instance_exec(&block)
432
- { anonymous: true, class: new_class }
433
- end
434
- define_method(name) do
435
- @included_hashes[name]
436
- end
437
- end
438
-
439
- def include_node(name, node_class, &block)
440
- included_nodes[name] = { class: node_class, anonymous: true, block: block }
441
- define_method(name) do
442
- path = @store_path + [:included_nodes, name]
443
- node_cid = Redux.fetch_by_path(*path)
444
- node_cid ? self.class.included_nodes[name][:class].node_from_cid(node_cid) : nil
445
- end
446
- end
447
-
448
- def load(props_hash = {})
449
- validate_props(props_hash)
450
- instance = self.new(validated_props: Isomorfeus::Data::Props.new(props_hash))
451
- self.promise_load(props_hash, instance) unless instance.loaded?
452
- instance
453
- end
454
-
455
- def on_load(&block)
456
- end
457
-
458
- def promise_load(props_hash = {}, instance = nil)
459
- unless instance
460
- validate_props(props_hash)
461
- instance = self.new(validated_props: Isomorfeus::Data::Props.new(props_hash))
462
- end
463
-
464
- props_json = instance.instance_variable_get(:@props_json)
465
-
466
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Data::Handler::GraphLoadHandler', self.name, props_json).then do |agent|
467
- if agent.processed
468
- agent.result
469
- else
470
- agent.processed = true
471
- if agent.response.key?(:error)
472
- `console.error(#{agent.response[:error].to_n})`
473
- raise agent.response[:error]
474
- end
475
- Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
476
- agent.result = instance
477
- end
478
- end
479
- end
480
-
481
- def query
482
- nil
483
- end
484
- end
485
- else # RUBY_ENGINE
486
- unless base == LucidGraph::Base
487
- base.prop :pub_sub_client, default: nil
488
- base.prop :current_user, default: nil
489
- end
490
-
491
- def initialize(store_path: nil, validated_props: nil)
492
- @props = validated_props
493
- @props_json = @props.to_json if @props
494
- @loaded = false
495
- @included_arrays = {}
496
- @included_collections = {}
497
- @included_hashes = {}
498
- @included_graphs = {}
499
- @included_nodes = {}
500
- @class_name = self.class.name
501
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
502
- end
503
-
504
- def loaded?
505
- @loaded
506
- end
507
-
508
- def edges
509
- all_edges = @edges.to_a
510
- @included_graphs.each_value { |graph| all_edges += graph.edges }
511
- all_edges.uniq!(&:to_cid)
512
- all_edges
513
- end
514
-
515
- def edges_as_cids
516
- edges.map { |edge| [edge.class.name, edge.id] }
517
- end
518
-
519
- def own_edges_as_cids
520
- @edges.map(&:to_cid).uniq
521
- end
522
-
523
- def nodes
524
- all_nodes = @nodes.to_a
525
- @included_graphs.each_value { |graph| all_nodes += graph.nodes }
526
- @included_collections.each_value { |collection| all_nodes += collection.nodes }
527
- included_nodes.each_value { |node| all_nodes << node }
528
- all_nodes.uniq!(&:to_cid)
529
- all_nodes
530
- end
531
-
532
- def nodes_as_cids
533
- nodes.map { |node| [node.class.name, node.id] }
534
- end
535
-
536
- def own_nodes_as_cids
537
- @nodes.map(&:to_cid).uniq
538
- end
539
-
540
- def method_missing(method_name, *args, &block)
541
- if method_name.start_with?('find_node_by_')
542
- attribute = method_name[13..-1] # remove 'find_node_by_'
543
- value = args[0]
544
- attribute_hash = { attribute => value }
545
- attribute_hash.merge!(args[1]) if args[1]
546
- find_node(attribute_hash)
547
- elsif method_name.start_with?('find_edge_by_')
548
- attribute = method_name[13..-1] # remove 'find_edge_by_'
549
- value = args[0]
550
- attribute_hash = { attribute => value }
551
- attribute_hash.merge!(args[1]) if args[1]
552
- find_edge(attribute_hash)
553
- else
554
- super
555
- end
556
- end
557
-
558
- base.instance_exec do
559
- attr_accessor :included_nodes
560
-
561
- def include_array(name, array_class = nil, &block)
562
- included_arrays[name] = if array_class
563
- { class: array_class }
564
- else
565
- new_class = Class.new(LucidArray::Base)
566
- new_class.instance_exec(&block)
567
- { anonymous: true, class: new_class }
568
- end
569
- define_method(name) do
570
- @included_arrays[name]
571
- end
572
- end
573
-
574
- def include_collection(name, collection_class = nil, &block)
575
- included_collections[name] = if collection_class
576
- { class: collection_class }
577
- else
578
- new_class = Class.new(LucidCollection::Base)
579
- new_class.instance_exec(&block)
580
- { anonymous: true, class: new_class }
581
- end
582
- define_method(name) do
583
- @included_collections[name]
584
- end
585
- end
586
-
587
- def include_graph(name, graph_class = nil, &block)
588
- included_graphs[name] = if graph_class
589
- { class: graph_class }
590
- else
591
- new_class = Class.new(LucidGraph::Base)
592
- new_class.instance_exec(&block)
593
- { anonymous: true, class: new_class }
594
- end
595
- define_method(name) do
596
- @included_graphs[name]
597
- end
598
- end
599
-
600
- def include_hash(name, hash_class = nil, &block)
601
- included_hashes[name] = if hash_class
602
- { class: hash_class }
603
- else
604
- new_class = Class.new(LucidHash::Base)
605
- new_class.instance_exec(&block)
606
- { anonymous: true, class: new_class }
607
- end
608
- define_method(name) do
609
- @included_hashes[name]
610
- end
611
- end
612
-
613
- def include_node(name, node_class, &block)
614
- included_nodes[name] = { class: node_class, anonymous: true, block: block }
615
- define_method(name) do
616
- included_nodes[name]
617
- end
618
- end
619
-
620
- def load(props_hash = {})
621
- validate_props(props_hash)
622
- instance = self.new(validated_props: Isomorfeus::Data::Props.new(props_hash))
623
- instance.instance_exec do
624
- nodes, edges = self.class.query_block.call(props_hash)
625
- @nodes = Set.new(nodes)
626
- @edges = Set.new(edges)
627
- self.class.included_arrays.each do |name, options|
628
- @included_arrays[name] = options[:class].load(props_hash)
629
- end
630
- self.class.included_collections.each do |name, options|
631
- @included_collections[name] = options[:class].load(props_hash)
632
- end
633
- self.class.included_graphs.each do |name, options|
634
- @included_graphs[name] = options[:class].load(props_hash)
635
- end
636
- self.class.included_hashes.each do |name, options|
637
- @included_hashes[name] = options[:class].load(props_hash)
638
- end
639
- self.class.included_nodes.each do |name, options|
640
- result = options[:block].call(props_hash)
641
- @included_nodes[name] = if result.class == options[:class]
642
- result
643
- elsif result.class == Hash
644
- options[:class].new(result)
645
- end
646
- end
647
- @loaded = true
648
- end
649
- instance
650
- end
651
-
652
- def on_load(&block)
653
- @on_load_block = block
654
- end
655
-
656
- def promise_load(props_hash = {}, instance = nil)
657
- instance = self.load(props_hash)
658
- result_promise = Promise.new
659
- result_promise.resolve(instance)
660
- result_promise
661
- end
662
-
663
- def query(&block)
664
- @query_block = block
665
- end
666
- end
667
- end # RUBY_ENGINE
668
- end
669
- end
670
- end
@@ -1,14 +0,0 @@
1
- module LucidHash
2
- class Base
3
- include LucidHash::Mixin
4
-
5
- if RUBY_ENGINE != 'opal'
6
- def self.inherited(base)
7
- Isomorfeus.add_valid_hash_class(base)
8
-
9
- base.prop :pub_sub_client, default: nil
10
- base.prop :current_user, default: nil
11
- end
12
- end
13
- end
14
- end