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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +47 -21
  3. data/README.md +38 -46
  4. data/lib/isomorfeus/data/attribute_support.rb +176 -176
  5. data/lib/isomorfeus/data/config.rb +79 -110
  6. data/lib/isomorfeus/data/element_validator.rb +147 -147
  7. data/lib/isomorfeus/data/ferret_accelerator.rb +66 -0
  8. data/lib/isomorfeus/data/field_support.rb +110 -0
  9. data/lib/isomorfeus/data/generic_class_api.rb +136 -116
  10. data/lib/isomorfeus/data/generic_instance_api.rb +150 -145
  11. data/lib/isomorfeus/data/hamster_accelerator.rb +87 -0
  12. data/lib/isomorfeus/data/hamster_storage_expander.rb +94 -0
  13. data/lib/isomorfeus/data/handler/generic.rb +134 -138
  14. data/lib/isomorfeus/data/reducer.rb +30 -30
  15. data/lib/isomorfeus/data/version.rb +4 -4
  16. data/lib/isomorfeus-data.rb +56 -64
  17. data/lib/isomorfeus_data/lucid_document/base.rb +10 -0
  18. data/lib/isomorfeus_data/lucid_document/mixin.rb +148 -0
  19. data/lib/isomorfeus_data/lucid_file/base.rb +10 -0
  20. data/lib/isomorfeus_data/lucid_file/mixin.rb +217 -0
  21. data/lib/isomorfeus_data/lucid_object/base.rb +10 -0
  22. data/lib/isomorfeus_data/lucid_object/mixin.rb +216 -0
  23. data/lib/isomorfeus_data/lucid_query/base.rb +10 -0
  24. data/lib/isomorfeus_data/lucid_query/mixin.rb +81 -0
  25. data/lib/isomorfeus_data/lucid_query_result.rb +97 -0
  26. data/opal/uri/common.rb +18 -0
  27. data/opal/uri/generic.rb +47 -0
  28. data/opal/uri.rb +29 -0
  29. metadata +85 -96
  30. data/lib/isomorfeus/data/handler/arango.rb +0 -56
  31. data/lib/isomorfeus/data/handler/object_call.rb +0 -40
  32. data/lib/isomorfeus/data/handler/object_store.rb +0 -40
  33. data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -13
  34. data/lib/isomorfeus_data/lucid_data/array/mixin.rb +0 -580
  35. data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -13
  36. data/lib/isomorfeus_data/lucid_data/collection/finders.rb +0 -83
  37. data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +0 -737
  38. data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -13
  39. data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +0 -234
  40. data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -13
  41. data/lib/isomorfeus_data/lucid_data/document/mixin.rb +0 -9
  42. data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -13
  43. data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +0 -286
  44. data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -13
  45. data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +0 -134
  46. data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +0 -747
  47. data/lib/isomorfeus_data/lucid_data/generic_collection.rb +0 -4
  48. data/lib/isomorfeus_data/lucid_data/generic_edge.rb +0 -4
  49. data/lib/isomorfeus_data/lucid_data/generic_edge_collection.rb +0 -4
  50. data/lib/isomorfeus_data/lucid_data/generic_node.rb +0 -4
  51. data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -13
  52. data/lib/isomorfeus_data/lucid_data/graph/finders.rb +0 -141
  53. data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +0 -489
  54. data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -13
  55. data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +0 -427
  56. data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -13
  57. data/lib/isomorfeus_data/lucid_data/link/mixin.rb +0 -9
  58. data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -13
  59. data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +0 -9
  60. data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -13
  61. data/lib/isomorfeus_data/lucid_data/node/mixin.rb +0 -232
  62. data/lib/isomorfeus_data/lucid_data/query/base.rb +0 -13
  63. data/lib/isomorfeus_data/lucid_data/query/mixin.rb +0 -83
  64. data/lib/isomorfeus_data/lucid_data/query_result.rb +0 -95
  65. data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -13
  66. data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +0 -9
  67. data/lib/lucid_arango/collection/base.rb +0 -13
  68. data/lib/lucid_arango/collection/mixin.rb +0 -18
  69. data/lib/lucid_arango/document/base.rb +0 -13
  70. data/lib/lucid_arango/document/mixin.rb +0 -9
  71. data/lib/lucid_arango/edge/base.rb +0 -13
  72. data/lib/lucid_arango/edge/mixin.rb +0 -18
  73. data/lib/lucid_arango/edge_collection/base.rb +0 -13
  74. data/lib/lucid_arango/edge_collection/mixin.rb +0 -18
  75. data/lib/lucid_arango/graph/base.rb +0 -13
  76. data/lib/lucid_arango/graph/mixin.rb +0 -18
  77. data/lib/lucid_arango/node/base.rb +0 -13
  78. data/lib/lucid_arango/node/mixin.rb +0 -79
  79. data/lib/lucid_arango/object/base.rb +0 -11
  80. data/lib/lucid_arango/object/mixin.rb +0 -158
  81. data/lib/lucid_arango/remote_object/base.rb +0 -11
  82. data/lib/lucid_arango/remote_object/mixin.rb +0 -17
  83. data/lib/lucid_arango/vertex/base.rb +0 -13
  84. data/lib/lucid_arango/vertex/mixin.rb +0 -9
@@ -1,4 +0,0 @@
1
- module LucidData
2
- class GenericCollection < LucidData::Collection::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module LucidData
2
- class GenericEdge < LucidData::Edge::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module LucidData
2
- class GenericEdgeCollection < LucidData::EdgeCollection::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module LucidData
2
- class GenericNode < LucidData::Node::Base
3
- end
4
- end
@@ -1,13 +0,0 @@
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
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,141 +0,0 @@
1
- module LucidData
2
- module Graph
3
- module Finders
4
- def find_node(attribute_hash = nil, &block)
5
- node_collections.each_value do |collection|
6
- node = collection.find(attribute_hash, &block)
7
- return node if node
8
- end
9
- nil
10
- end
11
- alias find_document find_node
12
- alias find_vertex find_node
13
-
14
- def find_nodes(attribute_hash = nil, &block)
15
- found_nodes = []
16
- node_collections.each_value do |collection|
17
- coll_nodes = collection.find_all(attribute_hash, &block)
18
- found_nodes.push(*coll_nodes)
19
- end
20
- found_nodes
21
- end
22
- alias find_documents find_nodes
23
- alias find_vertexes find_nodes
24
- alias find_vertices find_nodes
25
-
26
- def find_node_by_key(node_key)
27
- node_collections.each_value do |collection|
28
- node = collection.find_by_key(node_key)
29
- return node if node
30
- end
31
- nil
32
- end
33
- alias find_document_by_key find_node_by_key
34
- alias find_vertex_by_key find_node_by_key
35
-
36
- def find_node_by_sid(node)
37
- node_collections.each_value do |collection|
38
- node = collection.find_by_sid(node)
39
- return node if node
40
- end
41
- nil
42
- end
43
- alias find_document_by_sid find_node_by_sid
44
- alias find_vertex_by_sid find_node_by_sid
45
-
46
- def find_edge(attribute_hash = nil, &block)
47
- edge_collections.each_value do |collection|
48
- edge = collection.find(attribute_hash, &block)
49
- return edge if edge
50
- end
51
- nil
52
- end
53
- alias find_link find_edge
54
-
55
- def find_edges(attribute_hash = nil, &block)
56
- found_edges = []
57
- edge_collections.each_value do |collection|
58
- coll_edges = collection.find_all(attribute_hash, &block)
59
- found_edges.push(*coll_edges)
60
- end
61
- found_edges
62
- end
63
- alias find_links find_edges
64
-
65
- def find_edge_by_key(edge_key)
66
- edge_collections.each_value do |collection|
67
- edge = collection.find_by_key(edge_key)
68
- return edge if edge
69
- end
70
- nil
71
- end
72
- alias find_link_by_key find_edge_by_key
73
-
74
- def find_edge_by_sid(edge)
75
- edge_collections.each_value do |collection|
76
- edge = collection.find_by_sid(edge)
77
- return edge if edge
78
- end
79
- nil
80
- end
81
- alias find_link_by_key find_edge_by_key
82
-
83
- def find_edge_by_from(node)
84
- edge_collections.each_value do |collection|
85
- edge = collection.find_by_from(node)
86
- return edge if edge
87
- end
88
- nil
89
- end
90
- alias find_link_by_from find_edge_by_from
91
-
92
- def find_edge_by_to(node)
93
- edge_collections.each_value do |collection|
94
- edge = collection.find_by_to(node)
95
- return edge if edge
96
- end
97
- nil
98
- end
99
- alias find_link_by_to find_edge_by_to
100
-
101
- def find_edge_by_target(node)
102
- edge_collections.each_value do |collection|
103
- edge = collection.find_by_target(node)
104
- return edge if edge
105
- end
106
- nil
107
- end
108
- alias find_link_by_target find_edge_by_target
109
-
110
- def find_edges_by_from(node)
111
- found_edges = []
112
- edge_collections.each_value do |collection|
113
- coll_edges = collection.find_all_by_from(node)
114
- found_edges.push(*coll_edges)
115
- end
116
- found_edges
117
- end
118
- alias find_links_by_from find_edges_by_from
119
-
120
- def find_edges_by_to(node)
121
- found_edges = []
122
- edge_collections.each_value do |collection|
123
- coll_edges = collection.find_all_by_to(node)
124
- found_edges.push(*coll_edges)
125
- end
126
- found_edges
127
- end
128
- alias find_links_by_to find_edges_by_to
129
-
130
- def find_edges_by_target(node)
131
- found_edges = []
132
- edge_collections.each_value do |collection|
133
- coll_edges = collection.find_all_by_target(node)
134
- found_edges.push(*coll_edges)
135
- end
136
- found_edges
137
- end
138
- alias find_links_by_target find_edges_by_target
139
- end
140
- end
141
- end
@@ -1,489 +0,0 @@
1
- module LucidData
2
- module Graph
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::Graph::Finders)
10
-
11
- base.instance_exec do
12
- def edge_collections
13
- @edge_collections ||= {}
14
- end
15
-
16
- def node_collections
17
- @node_collections ||= {}
18
- end
19
-
20
- def nodes(access_name, validate_hash = {})
21
- node_collections[access_name] = validate_hash
22
-
23
- define_method(access_name) do
24
- node_collections[access_name]
25
- end
26
-
27
- define_method("#{access_name}=") do |collection|
28
- _validate_node_collection(access_name, collection)
29
- @_changed = true
30
- node_collections[access_name] = collection
31
- node_collections[access_name].graph = self
32
- node_collections[access_name]
33
- end
34
-
35
- define_singleton_method("valid_#{access_name}?") do |collection|
36
- _validate_node_collection(access_name, collection)
37
- rescue
38
- false
39
- end
40
- end
41
- alias documents nodes
42
- alias vertices nodes
43
- alias vertexes nodes
44
-
45
- def _validate_nodes(nodes_hash_or_array)
46
- if nodes_hash_or_array.class == ::Hash
47
- nodes_hash_or_array.each do |access_name, collection|
48
- _validate_node_collection(access_name, collection)
49
- end
50
- else
51
- _validate_node_collection(:nodes, nodes_hash_or_array)
52
- end
53
- end
54
-
55
- def _validate_node_collection(access_name, collection)
56
- unless node_collections.key?(access_name) || access_name == :nodes
57
- Isomorfeus.raise_error(message: "#{self.name}: No such node collection declared: '#{access_name}'!")
58
- end
59
- Isomorfeus::Data::ElementValidator.new(self.name, collection, node_collections[access_name]).validate! if node_collections[access_name]
60
- end
61
-
62
- def edges(access_name, validate_hash = {})
63
- edge_collections[access_name] = validate_hash
64
-
65
- define_method(access_name) do
66
- edge_collections[access_name]
67
- end
68
-
69
- define_method("#{access_name}=") do |collection|
70
- _validate_edge_collection(access_name, collection)
71
- @_changed = true
72
- edge_collections[access_name] = collection
73
- edge_collections[access_name].graph = self
74
- edge_collections[access_name]
75
- end
76
-
77
- define_singleton_method("valid_#{access_name}?") do |collection|
78
- _validate_edge_collection(access_name, collection)
79
- rescue
80
- false
81
- end
82
- end
83
- alias links edges
84
-
85
- def _validate_edges(edges_hash_or_array)
86
- if edges_hash_or_array.class == ::Hash
87
- edges_hash_or_array.each do |access_name, collection|
88
- _validate_edge_collection(access_name, collection)
89
- end
90
- else
91
- _validate_edge_collection(:edges, edges_hash_or_array)
92
- end
93
- end
94
-
95
- def _validate_edge_collection(access_name, collection)
96
- unless edge_collections.key?(access_name) || access_name == :edges
97
- Isomorfeus.raise_error(message: "#{self.name}: No such edge collection declared: '#{access_name}'!")
98
- end
99
- Isomorfeus::Data::ElementValidator.new(self.name, collection, edge_collections[access_name]).validate! if edge_collections[access_name]
100
- end
101
- end
102
-
103
- def _validate_edges(edges_hash_or_array)
104
- self.class._validate_edges(edges_hash_or_array)
105
- end
106
-
107
- def _validate_edge_collection(access_name, collection)
108
- self.class._validate_edge_collection(access_name, collection)
109
- end
110
-
111
- def _validate_nodes(nodes_hash_or_array)
112
- self.class._validate_nodes(nodes_hash_or_array)
113
- end
114
-
115
- def _validate_node_collection(access_name, collection)
116
- self.class._validate_node_collection(access_name, collection)
117
- end
118
-
119
- def method_missing(method_name, *args, &block)
120
- method_name_s = method_name.to_s
121
- if method_name_s.start_with?('find_edge_by_') || method_name_s.start_with?('find_link_by_')
122
- attribute = method_name_s[13..-1] # remove 'find_by_'
123
- value = args[0]
124
- attribute_hash = { attribute => value }
125
- attribute_hash.merge!(args[1]) if args[1]
126
- find_edge(attribute_hash)
127
- elsif method_name_s.start_with?('find_node_by_') || method_name_s.start_with?('find_document_by_') || method_name_s.start_with?('find_vertex_by_')
128
- attribute = if method_name_s.start_with?('find_node_by_')
129
- method_name_s[13..-1]
130
- elsif method_name_s.start_with?('find_document_by_')
131
- method_name_s[17..-1]
132
- elsif method_name_s.start_with?('find_vertex_by_')
133
- method_name_s[15..-1]
134
- end
135
- value = args[0]
136
- attribute_hash = { attribute => value }
137
- attribute_hash.merge!(args[1]) if args[1]
138
- find_node(attribute_hash)
139
- else
140
- super(method_name, *args, &block)
141
- end
142
- end
143
-
144
- def edges_for_node(node)
145
- node_edges = []
146
- edge_collections.each_value do |collection|
147
- node_edges.push(*collection.edges_for_node(node))
148
- end
149
- node_edges
150
- end
151
-
152
- def linked_nodes_for_node(node)
153
- node_edges = edges_for_node(node)
154
- nodes = []
155
- node_sid = node.to_sid
156
- node_edges.each do |edge|
157
- from_sid = edge.from.to_sid
158
- to_sid = edge.to.to_sid
159
- if to_sid == node_sid
160
- nodes << edge.from
161
- elsif from_sid == node_sid
162
- nodes << edge.to
163
- end
164
- end
165
- nodes
166
- end
167
-
168
- def node_from_sid(sid)
169
- node = nil
170
- node_collections.each_value do |collection|
171
- node = collection.node_from_sid(sid)
172
- break if node
173
- end
174
- node
175
- end
176
- alias document_from_sid node_from_sid
177
- alias vertex_from_sid node_from_sid
178
-
179
- def nodes
180
- all_nodes = []
181
- node_collections.each_value do |collection|
182
- all_nodes.push(*collection.nodes)
183
- end
184
- all_nodes
185
- end
186
- alias documents nodes
187
- alias vertices nodes
188
- alias vertexes nodes
189
-
190
- def edges
191
- all_edges = []
192
- edge_collections.each_value do |collection|
193
- all_edges.push(*collection.edges)
194
- end
195
- all_edges
196
- end
197
- alias links edges
198
-
199
- def changed?
200
- @_changed
201
- end
202
-
203
- def changed!
204
- @_composition.changed! if @_composition
205
- @_changed = true
206
- end
207
-
208
- def composition
209
- @_composition
210
- end
211
-
212
- def composition=(c)
213
- @_composition = c
214
- end
215
-
216
- def to_transport
217
- hash = { 'attributes' => _get_selected_attributes, 'nodes' => {}, 'edges' => {} }
218
- node_collections.each do |name, collection|
219
- hash['nodes'][name.to_s] = collection.to_sid if collection
220
- end
221
- edge_collections.each do |name, collection|
222
- hash['edges'][name.to_s] = collection.to_sid if collection
223
- end
224
- hash.merge!('revision' => revision) if revision
225
- result = { @class_name => { @key => hash }}
226
- result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
227
- result
228
- end
229
-
230
- def included_items_to_transport
231
- hash = {}
232
- node_collections.each_value do |collection|
233
- if collection
234
- hash.deep_merge!(collection.to_transport)
235
- hash.deep_merge!(collection.included_items_to_transport)
236
- end
237
- end
238
- edge_collections.each_value do |collection|
239
- if collection
240
- hash.deep_merge!(collection.to_transport)
241
- hash.deep_merge!(collection.included_items_to_transport)
242
- end
243
- end
244
- hash
245
- end
246
-
247
- if RUBY_ENGINE == 'opal'
248
- def initialize(key:, revision: nil, attributes: nil, edges: nil, links: nil, nodes: nil, documents: nil, vertices: nil, vertexes: nil, composition: nil)
249
- @key = key.to_s
250
- @class_name = self.class.name
251
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
252
- _update_paths
253
- @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
254
- @_composition = composition
255
- @_changed = false
256
-
257
- loaded = loaded?
258
-
259
- if attributes
260
- _validate_attributes(attributes)
261
- if loaded
262
- raw_attributes = Redux.fetch_by_path(*@_store_path)
263
- if `raw_attributes === null`
264
- @_changed_attributes = !attributes ? {} : attributes
265
- elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
266
- @_changed_attributes = attributes
267
- end
268
- else
269
- @_changed_attributes = attributes
270
- end
271
- else
272
- @_changed_attributes = {}
273
- end
274
-
275
- # nodes
276
- @_node_collections = {}
277
- nodes = nodes || documents || vertices || vertexes
278
- if nodes && loaded
279
- _validate_nodes(nodes)
280
- if nodes.class == ::Hash
281
- self.class.node_collections.each_key do |access_name|
282
- if nodes.key?(access_name)
283
- collection = nodes[access_name]
284
- @_node_collections[access_name] = if collection.respond_to?(:to_sid)
285
- collection
286
- else
287
- Isomorfeus.instance_from_sid(collection)
288
- end
289
- end
290
- end
291
- else
292
- @_node_collections[:nodes] = if nodes.respond_to?(:to_sid)
293
- nodes
294
- else
295
- Isomorfeus.instance_from_sid(nodes)
296
- end
297
- end
298
- elsif loaded
299
- self.class.node_collections.each_key do |access_name|
300
- sid = Redux.fetch_by_path(*(@_nodes_path + [access_name]))
301
- @_node_collections[access_name] = Isomorfeus.instance_from_sid(sid) if sid
302
- end
303
- end
304
- @_node_collections.each_value { |collection| collection.graph = self }
305
-
306
- # edges
307
- @_edge_collections = {}
308
- edges = edges || links
309
- if edges && loaded
310
- _validate_edges(edges)
311
- if edges.class == ::Hash
312
- self.class.edge_collections.each_key do |access_name|
313
- if edges.key?(access_name)
314
- collection = edges[access_name]
315
- @_edge_collections[access_name] = if collection.respond_to?(:to_sid)
316
- collection
317
- else
318
- Isomorfeus.instance_from_sid(collection)
319
- end
320
- end
321
- end
322
- else
323
- @_edge_collections[:edges] = if edges.respond_to?(:to_sid)
324
- edges
325
- else
326
- Isomorfeus.instance_from_sid(edges)
327
- end
328
- end
329
- elsif loaded
330
- self.class.edge_collections.each_key do |access_name|
331
- sid = Redux.fetch_by_path(*(@_edges_path + [access_name]))
332
- @_edge_collections[access_name] = Isomorfeus.instance_from_sid(sid) if sid
333
- end
334
- end
335
- @_edge_collections.each_value { |collection| collection.graph = self }
336
- end
337
-
338
- def _init_node_collections
339
- keys = self.class.node_collections.keys
340
- keys << :nodes if keys.empty?
341
- keys.each do |access_name|
342
- sid = Redux.fetch_by_path(*(@_nodes_path + [access_name]))
343
- if sid
344
- @_node_collections[access_name] = Isomorfeus.instance_from_sid(sid)
345
- @_node_collections[access_name].graph = self
346
- end
347
- end
348
- end
349
-
350
- def _init_edge_collections
351
- keys = self.class.edge_collections.keys
352
- keys << :edges if keys.empty?
353
- keys.each do |access_name|
354
- sid = Redux.fetch_by_path(*(@_edges_path + [access_name]))
355
- if sid
356
- @_edge_collections[access_name] = Isomorfeus.instance_from_sid(sid)
357
- @_edge_collections[access_name].graph = self
358
- end
359
- end
360
- end
361
-
362
- def _load_from_store!
363
- @_changed = false
364
- @_changed_attributes = {}
365
- @_node_collections = {}
366
- @_edge_collections = {}
367
- nil
368
- end
369
-
370
- def _update_paths
371
- @_store_path = [:data_state, @class_name, @key, :attributes]
372
- @_edges_path = [:data_state, @class_name, @key, :edges]
373
- @_nodes_path = [:data_state, @class_name, @key, :nodes]
374
- end
375
-
376
- def edge_collections
377
- _init_edge_collections if @_edge_collections.empty?
378
- @_edge_collections
379
- end
380
- alias link_collections edge_collections
381
-
382
- def node_collections
383
- _init_node_collections if @_node_collections.empty?
384
- @_node_collections
385
- end
386
- alias document_collections node_collections
387
- alias vertex_collections node_collections
388
- else # RUBY_ENGINE
389
- Isomorfeus.add_valid_data_class(base) unless base == LucidData::Graph::Base
390
-
391
- base.instance_exec do
392
- def instance_from_transport(instance_data, included_items_data)
393
- key = instance_data[self.name].keys.first
394
- revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
395
- attributes = instance_data[self.name][key].key?('attributes') ? instance_data[self.name][key]['attributes'].transform_keys!(&:to_sym) : nil
396
-
397
- nodes_hash = instance_data[self.name][key].key?('nodes') ? instance_data[self.name][key]['nodes'] : {}
398
- edges_hash = instance_data[self.name][key].key?('edges') ? instance_data[self.name][key]['edges'] : {}
399
-
400
- nodes_edges = [{},{}]
401
- [nodes_hash, edges_hash].each_with_index do |hash, hash_index|
402
- hash.each do |name, value|
403
- namsy = name.to_sym
404
- nodes_edges[namsy] = []
405
- value.each do |sid|
406
- node_class_name = sid[0]
407
- node_key = sid[1]
408
- Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Not a valid LucidData class!") unless Isomorfeus.valid_data_class_name?(node_class_name)
409
- if included_items_data.key?(node_class_name) && included_items_data[node_class_name].key?(node_key)
410
- node_class = Isomorfeus.cached_data_class(node_class_name)
411
- Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Cannot get class!") unless node_class
412
- node = node_class.instance_from_transport({ node_class_name => { node_key => included_items_data[node_class_name][node_key] }}, included_items_data)
413
- Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name} with key #{node_key} could not be extracted from transport data!") unless node
414
- nodes_edges[hash_index][namsy] << node
415
- end
416
- end
417
- end
418
- end
419
-
420
- new(key: key, revision: revision, attributes: attributes, nodes: nodes_edges[0], edges: nodes_edges[1])
421
- end
422
- end
423
-
424
- def initialize(key:, revision: nil, attributes: nil, edges: nil, links: nil, nodes: nil, documents: nil, vertices: nil, vertexes: nil,
425
- composition: nil)
426
- @key = key.to_s
427
- @class_name = self.class.name
428
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
429
- @_revision = revision
430
- @_changed = false
431
- @_composition = composition
432
- attributes = {} unless attributes
433
- _validate_attributes(attributes) if attributes.any?
434
- @_raw_attributes = attributes
435
-
436
- # nodes
437
- @_node_collections = {}
438
- nodes = nodes || documents || vertices || vertexes
439
- if nodes.class == ::Hash
440
- _validate_nodes(nodes)
441
- self.class.node_collections.each_key do |access_name|
442
- if nodes.key?(access_name)
443
- @_node_collections[access_name] = nodes[access_name]
444
- @_node_collections[access_name].graph = self
445
- end
446
- end
447
- else
448
- _validate_nodes(nodes) if nodes
449
- @_node_collections[:nodes] = nodes
450
- @_node_collections[:nodes].graph = self if @_node_collections[:nodes].respond_to?(:graph=)
451
- end
452
-
453
- # edges
454
- @_edge_collections = {}
455
- edges = edges || links
456
- if edges.class == ::Hash
457
- _validate_edges(edges)
458
- self.class.edge_collections.each_key do |access_name|
459
- if edges.key?(access_name)
460
- @_edge_collections[access_name] = edges[access_name]
461
- @_edge_collections[access_name].graph = self
462
- end
463
- end
464
- else
465
- _validate_edges(edges) if edges
466
- @_edge_collections[:edges] = edges
467
- @_edge_collections[:edges].graph = self if @_edge_collections[:edges].respond_to?(:graph=)
468
- end
469
- end
470
-
471
- def _unchange!
472
- @_changed = false
473
- end
474
-
475
- def edge_collections
476
- @_edge_collections
477
- end
478
- alias link_collections edge_collections
479
-
480
- def node_collections
481
- @_node_collections
482
- end
483
- alias document_collections node_collections
484
- alias vertex_collections node_collections
485
- end # RUBY_ENGINE
486
- end
487
- end
488
- end
489
- end
@@ -1,13 +0,0 @@
1
- module LucidData
2
- module Hash
3
- class Base
4
- include LucidData::Hash::Mixin
5
-
6
- if RUBY_ENGINE != 'opal'
7
- def self.inherited(base)
8
- Isomorfeus.add_valid_data_class(base)
9
- end
10
- end
11
- end
12
- end
13
- end