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,141 @@
|
|
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
|
+
nodes = collection.find_all(attribute_hash, &block)
|
18
|
+
found_nodes.push(*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
|
+
edges = collection.find_all(attribute_hash, &block)
|
59
|
+
found_edges.push(*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
|
@@ -0,0 +1,401 @@
|
|
1
|
+
module LucidData
|
2
|
+
module Graph
|
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::Graph::Finders)
|
11
|
+
|
12
|
+
base.instance_exec do
|
13
|
+
def edge_collections
|
14
|
+
@edge_collections ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def node_collections
|
18
|
+
@node_collections ||= {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def nodes(access_name, collection_class = nil)
|
22
|
+
node_collections[access_name] = collection_class
|
23
|
+
|
24
|
+
define_method(access_name) do
|
25
|
+
node_collections[access_name]
|
26
|
+
end
|
27
|
+
|
28
|
+
define_method("#{access_name}=") do |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
|
+
if collection_class
|
36
|
+
singular_access_name = access_name.to_s.singularize
|
37
|
+
define_singleton_method("valid_#{singular_access_name}?") do |node|
|
38
|
+
collection_class.valid_node?(node)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
alias documents nodes
|
43
|
+
alias vertices nodes
|
44
|
+
alias vertexes nodes
|
45
|
+
|
46
|
+
def edges(access_name, collection_class = nil)
|
47
|
+
edge_collections[access_name] = collection_class
|
48
|
+
|
49
|
+
define_method(access_name) do
|
50
|
+
edge_collections[access_name]
|
51
|
+
end
|
52
|
+
|
53
|
+
define_method("#{access_name}=") do |collection|
|
54
|
+
@_changed = true
|
55
|
+
edge_collections[access_name] = collection
|
56
|
+
edge_collections[access_name].graph = self
|
57
|
+
edge_collections[access_name]
|
58
|
+
end
|
59
|
+
|
60
|
+
if collection_class
|
61
|
+
singular_access_name = access_name.to_s.singularize
|
62
|
+
define_singleton_method("valid_#{singular_access_name}?") do |edge|
|
63
|
+
collection_class.valid_edge?(edge)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
alias links edges
|
68
|
+
end
|
69
|
+
|
70
|
+
def method_missing(method_name, *args, &block)
|
71
|
+
method_name_s = method_name.to_s
|
72
|
+
if method_name_s.start_with?('find_edge_by_') || method_name_s.start_with?('find_link_by_')
|
73
|
+
attribute = method_name_s[13..-1] # remove 'find_by_'
|
74
|
+
value = args[0]
|
75
|
+
attribute_hash = { attribute => value }
|
76
|
+
attribute_hash.merge!(args[1]) if args[1]
|
77
|
+
find_edge(attribute_hash)
|
78
|
+
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_')
|
79
|
+
attribute = if method_name_s.start_with?('find_node_by_')
|
80
|
+
method_name_s[13..-1]
|
81
|
+
elsif method_name_s.start_with?('find_document_by_')
|
82
|
+
method_name_s[17..-1]
|
83
|
+
elsif method_name_s.start_with?('find_vertex_by_')
|
84
|
+
method_name_s[15..-1]
|
85
|
+
end
|
86
|
+
value = args[0]
|
87
|
+
attribute_hash = { attribute => value }
|
88
|
+
attribute_hash.merge!(args[1]) if args[1]
|
89
|
+
find_node(attribute_hash)
|
90
|
+
else
|
91
|
+
super(method_name, *args, &block)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def edges_for_node(node)
|
96
|
+
node_edges = []
|
97
|
+
edge_collections.each_value do |collection|
|
98
|
+
node_edges.push(*collection.edges_for_node(node))
|
99
|
+
end
|
100
|
+
node_edges
|
101
|
+
end
|
102
|
+
|
103
|
+
def linked_nodes_for_node(node)
|
104
|
+
node_edges = edges_for_node(node)
|
105
|
+
nodes = []
|
106
|
+
node_sid = node.to_sid
|
107
|
+
node_edges.each do |edge|
|
108
|
+
from_sid = edge.from.to_sid
|
109
|
+
to_sid = edge.to.to_sid
|
110
|
+
if to_sid == node_sid
|
111
|
+
nodes << edge.from
|
112
|
+
elsif from_sid == node_sid
|
113
|
+
nodes << edge.to
|
114
|
+
end
|
115
|
+
end
|
116
|
+
nodes
|
117
|
+
end
|
118
|
+
|
119
|
+
def node_from_sid(sid)
|
120
|
+
node = nil
|
121
|
+
node_collections.each_value do |collection|
|
122
|
+
node = collection.node_from_sid(sid)
|
123
|
+
break if node
|
124
|
+
end
|
125
|
+
node
|
126
|
+
end
|
127
|
+
alias document_from_sid node_from_sid
|
128
|
+
alias vertex_from_sid node_from_sid
|
129
|
+
|
130
|
+
def nodes
|
131
|
+
all_nodes = []
|
132
|
+
node_collections.each_value do |collection|
|
133
|
+
all_nodes.push(*collection.nodes)
|
134
|
+
end
|
135
|
+
all_nodes
|
136
|
+
end
|
137
|
+
alias documents nodes
|
138
|
+
alias vertices nodes
|
139
|
+
alias vertexes nodes
|
140
|
+
|
141
|
+
def edges
|
142
|
+
all_edges = []
|
143
|
+
edge_collections.each_value do |collection|
|
144
|
+
all_edges.push(*collection.edges)
|
145
|
+
end
|
146
|
+
all_edges
|
147
|
+
end
|
148
|
+
alias links edges
|
149
|
+
|
150
|
+
def changed?
|
151
|
+
@_changed
|
152
|
+
end
|
153
|
+
|
154
|
+
def changed!
|
155
|
+
@_composition.changed! if @_composition
|
156
|
+
@_changed = true
|
157
|
+
end
|
158
|
+
|
159
|
+
def composition
|
160
|
+
@_composition
|
161
|
+
end
|
162
|
+
|
163
|
+
def composition=(c)
|
164
|
+
@_composition = c
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_transport
|
168
|
+
hash = { 'attributes' => _get_selected_attributes, 'nodes' => {}, 'edges' => {} }
|
169
|
+
node_collections.each { |name, collection| hash['nodes'][name.to_s] = collection.to_sid }
|
170
|
+
edge_collections.each { |name, collection| hash['edges'][name.to_s] = collection.to_sid }
|
171
|
+
hash.merge!('revision' => revision) if revision
|
172
|
+
{ @class_name => { @key => hash }}
|
173
|
+
end
|
174
|
+
|
175
|
+
def included_items_to_transport
|
176
|
+
hash = {}
|
177
|
+
node_collections.each_value do |collection|
|
178
|
+
hash.deep_merge!(collection.to_transport)
|
179
|
+
hash.deep_merge!(collection.included_items_to_transport)
|
180
|
+
end
|
181
|
+
edge_collections.each_value do |collection|
|
182
|
+
hash.deep_merge!(collection.to_transport)
|
183
|
+
hash.deep_merge!(collection.included_items_to_transport)
|
184
|
+
end
|
185
|
+
hash
|
186
|
+
end
|
187
|
+
|
188
|
+
if RUBY_ENGINE == 'opal'
|
189
|
+
def initialize(key:, revision: nil, attributes: nil, edges: nil, links: nil, nodes: nil, documents: nil, vertices: nil, vertexes: nil, composition: nil)
|
190
|
+
@key = key.to_s
|
191
|
+
@class_name = self.class.name
|
192
|
+
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
193
|
+
@_store_path = [:data_state, @class_name, @key, :attributes]
|
194
|
+
@_edges_path = [:data_state, @class_name, @key, :edges]
|
195
|
+
@_nodes_path = [:data_state, @class_name, @key, :nodes]
|
196
|
+
@_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
|
197
|
+
@_composition = composition
|
198
|
+
@_changed = false
|
199
|
+
|
200
|
+
loaded = loaded?
|
201
|
+
|
202
|
+
if attributes
|
203
|
+
attributes.each { |a,v| _validate_attribute(a, v) }
|
204
|
+
if loaded
|
205
|
+
raw_attributes = Redux.fetch_by_path(*@_store_path)
|
206
|
+
if `raw_attributes === null`
|
207
|
+
@_changed_attributes = !attributes ? {} : attributes
|
208
|
+
elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
|
209
|
+
@_changed_attributes = attributes
|
210
|
+
end
|
211
|
+
else
|
212
|
+
@_changed_attributes = attributes
|
213
|
+
end
|
214
|
+
else
|
215
|
+
@_changed_attributes = {}
|
216
|
+
end
|
217
|
+
|
218
|
+
# nodes
|
219
|
+
@_node_collections = {}
|
220
|
+
nodes = nodes || documents || vertices || vertexes
|
221
|
+
if nodes && loaded
|
222
|
+
if nodes.class == ::Hash
|
223
|
+
self.class.node_collections.each_key do |access_name|
|
224
|
+
if nodes.key?(access_name)
|
225
|
+
collection = nodes[access_name]
|
226
|
+
@_node_collections[access_name] = if collection.respond_to?(:to_sid)
|
227
|
+
collection
|
228
|
+
else
|
229
|
+
Isomorfeus.instance_from_sid(collection)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
else
|
234
|
+
@_node_collections[:nodes] = if nodes.respond_to?(:to_sid)
|
235
|
+
nodes
|
236
|
+
else
|
237
|
+
Isomorfeus.instance_from_sid(nodes)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
elsif loaded
|
241
|
+
self.class.node_collections.each_key do |access_name|
|
242
|
+
sid = Redux.fetch_by_path(*(@_nodes_path + [access_name]))
|
243
|
+
@_node_collections[access_name] = Isomorfeus.instance_from_sid(sid) if sid
|
244
|
+
end
|
245
|
+
end
|
246
|
+
@_node_collections.each_value { |collection| collection.graph = self }
|
247
|
+
|
248
|
+
# edges
|
249
|
+
@_edge_collections = {}
|
250
|
+
edges = edges || links
|
251
|
+
if edges && loaded
|
252
|
+
if edges.class == ::Hash
|
253
|
+
self.class.edge_collections.each_key do |access_name|
|
254
|
+
if edges.key?(access_name)
|
255
|
+
collection = edges[access_name]
|
256
|
+
@_edge_collections[access_name] = if collection.respond_to?(:to_sid)
|
257
|
+
collection
|
258
|
+
else
|
259
|
+
Isomorfeus.instance_from_sid(collection)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
else
|
264
|
+
@_edge_collections[:edges] = if edges.respond_to?(:to_sid)
|
265
|
+
edges
|
266
|
+
else
|
267
|
+
Isomorfeus.instance_from_sid(edges)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
elsif loaded
|
271
|
+
self.class.edge_collections.each_key do |access_name|
|
272
|
+
sid = Redux.fetch_by_path(*(@_edges_path + [access_name]))
|
273
|
+
@_edge_collections[access_name] = Isomorfeus.instance_from_sid(sid) if sid
|
274
|
+
end
|
275
|
+
end
|
276
|
+
@_edge_collections.each_value { |collection| collection.graph = self }
|
277
|
+
end
|
278
|
+
|
279
|
+
def _init_node_collections
|
280
|
+
keys = self.class.node_collections.keys
|
281
|
+
keys << :nodes if keys.empty?
|
282
|
+
keys.each do |access_name|
|
283
|
+
sid = Redux.fetch_by_path(*(@_nodes_path + [access_name]))
|
284
|
+
if sid
|
285
|
+
@_node_collections[access_name] = Isomorfeus.instance_from_sid(sid)
|
286
|
+
@_node_collections[access_name].graph = self
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def _init_edge_collections
|
292
|
+
keys = self.class.node_collections.keys
|
293
|
+
keys << :edges if keys.empty?
|
294
|
+
keys.each do |access_name|
|
295
|
+
sid = Redux.fetch_by_path(*(@_edges_path + [access_name]))
|
296
|
+
if sid
|
297
|
+
@_edge_collections[access_name] = Isomorfeus.instance_from_sid(sid)
|
298
|
+
@_edge_collections[access_name].graph = self
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def _load_from_store!
|
304
|
+
@_changed = false
|
305
|
+
@_changed_attributes = {}
|
306
|
+
@_node_collections = {}
|
307
|
+
@_edge_collections = {}
|
308
|
+
nil
|
309
|
+
end
|
310
|
+
|
311
|
+
def edge_collections
|
312
|
+
_init_edge_collections if @_edge_collections.empty?
|
313
|
+
@_edge_collections
|
314
|
+
end
|
315
|
+
alias link_collections edge_collections
|
316
|
+
|
317
|
+
def node_collections
|
318
|
+
_init_node_collections if @_node_collections.empty?
|
319
|
+
@_node_collections
|
320
|
+
end
|
321
|
+
alias document_collections node_collections
|
322
|
+
alias vertex_collections node_collections
|
323
|
+
else # RUBY_ENGINE
|
324
|
+
unless base == LucidData::Graph::Base
|
325
|
+
Isomorfeus.add_valid_data_class(base)
|
326
|
+
base.prop :pub_sub_client, default: nil
|
327
|
+
base.prop :current_user, default: Anonymous.new
|
328
|
+
end
|
329
|
+
|
330
|
+
base.instance_exec do
|
331
|
+
def load(key:, pub_sub_client: nil, current_user: nil)
|
332
|
+
data = instance_exec(key: key, &@_load_block)
|
333
|
+
revision = nil
|
334
|
+
revision = data.delete(:revision) if data.key?(:revision)
|
335
|
+
nodes = data.delete(:nodes)
|
336
|
+
edges = data.delete(:edges)
|
337
|
+
attributes = data.delete(:attributes)
|
338
|
+
self.new(key: key, revision: revision, edges: edges, nodes: nodes, attributes: attributes)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def initialize(key:, revision: nil, attributes: nil, edges: nil, links: nil, nodes: nil, documents: nil, vertices: nil, vertexes: nil, composition: nil)
|
343
|
+
@key = key.to_s
|
344
|
+
@class_name = self.class.name
|
345
|
+
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
346
|
+
@_revision = revision
|
347
|
+
@_changed = false
|
348
|
+
@_composition = composition
|
349
|
+
@_validate_attributes = self.class.attribute_conditions.any?
|
350
|
+
attributes = {} unless attributes
|
351
|
+
if @_validate_attributes
|
352
|
+
attributes.each { |a,v| _validate_attribute(a, v) }
|
353
|
+
end
|
354
|
+
@_raw_attributes = attributes
|
355
|
+
|
356
|
+
# nodes
|
357
|
+
@_node_collections = {}
|
358
|
+
nodes = nodes || documents || vertices || vertexes
|
359
|
+
if nodes.class == ::Hash
|
360
|
+
self.class.node_collections.each_key do |access_name|
|
361
|
+
if nodes.key?(access_name)
|
362
|
+
@_node_collections[access_name] = nodes[access_name]
|
363
|
+
@_node_collections[access_name].graph = self
|
364
|
+
end
|
365
|
+
end
|
366
|
+
else
|
367
|
+
@_node_collections[:nodes] = nodes ? nodes : []
|
368
|
+
@_node_collections[:nodes].graph = self if @_node_collections[:nodes].respond_to?(:graph=)
|
369
|
+
end
|
370
|
+
|
371
|
+
# edges
|
372
|
+
@_edge_collections = {}
|
373
|
+
edges = edges || links
|
374
|
+
if edges.class == ::Hash
|
375
|
+
self.class.edge_collections.each_key do |access_name|
|
376
|
+
if edges.key?(access_name)
|
377
|
+
@_edge_collections[access_name] = edges[access_name]
|
378
|
+
@_edge_collections[access_name].graph = self
|
379
|
+
end
|
380
|
+
end
|
381
|
+
else
|
382
|
+
@_edge_collections[:edges] = edges ? edges : []
|
383
|
+
@_edge_collections[:edges].graph = self if @_edge_collections[:edges].respond_to?(:graph=)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
def edge_collections
|
388
|
+
@_edge_collections
|
389
|
+
end
|
390
|
+
alias link_collections edge_collections
|
391
|
+
|
392
|
+
def node_collections
|
393
|
+
@_node_collections
|
394
|
+
end
|
395
|
+
alias document_collections node_collections
|
396
|
+
alias vertex_collections node_collections
|
397
|
+
end # RUBY_ENGINE
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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
|
+
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
|