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
@@ -0,0 +1,185 @@
1
+ module LucidData
2
+ module Composition
3
+ module Mixin
4
+ # TODO nodes -> documents
5
+ # TODO include -> compose dsl
6
+ # TODO inline store path
7
+ def self.included(base)
8
+ base.extend(LucidPropDeclaration::Mixin)
9
+ base.include(Isomorfeus::Data::AttributeSupport)
10
+ base.extend(Isomorfeus::Data::GenericClassApi)
11
+ base.include(Isomorfeus::Data::GenericInstanceApi)
12
+
13
+ base.instance_exec do
14
+ def parts
15
+ @parts ||= {}
16
+ end
17
+
18
+ def compose_with(access_name, part_class = nil)
19
+ parts[access_name] = part_class
20
+
21
+ define_method(access_name) do
22
+ parts[access_name]
23
+ end
24
+
25
+ define_method("#{access_name}=") do |part|
26
+ @_changed = true
27
+ parts[access_name] = part
28
+ parts[access_name].composition = self
29
+ parts[access_name]
30
+ end
31
+ end
32
+ end
33
+
34
+ def changed?
35
+ @_changed
36
+ end
37
+
38
+ def changed!
39
+ @_changed = true
40
+ end
41
+
42
+ def to_transport
43
+ hash = { 'attributes' => _get_selected_attributes, 'parts' => {} }
44
+ hash.merge!('revision' => revision) if revision
45
+ parts.each do |name, instance|
46
+ hash['parts'][name.to_s] = instance.to_sid
47
+ end
48
+ { @class_name => { @key => hash }}
49
+ end
50
+
51
+ def included_items_to_transport
52
+ hash = {}
53
+ parts.each_value do |instance|
54
+ hash.deep_merge!(instance.to_transport)
55
+ hash.deep_merge!(instance.included_items_to_transport) if instance.respond_to?(:included_items_to_transport)
56
+ end
57
+ hash
58
+ end
59
+
60
+ if RUBY_ENGINE == 'opal'
61
+ def initialize(key:, revision: nil, attributes: nil, parts: nil)
62
+ @key = key.to_s
63
+ @class_name = self.class.name
64
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
65
+ @_store_path = [:data_state, @class_name, @key, :attributes]
66
+ @_parts_path = [:data_state, @class_name, @key, :parts]
67
+ @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
68
+ @_changed = false
69
+
70
+ loaded = loaded?
71
+
72
+ if attributes
73
+ attributes.each { |a,v| _validate_attribute(a, v) }
74
+ if loaded
75
+ raw_attributes = Redux.fetch_by_path(*@_store_path)
76
+ if `raw_attributes === null`
77
+ @_changed_attributes = !attributes ? {} : attributes
78
+ elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
79
+ @_changed_attributes = attributes
80
+ end
81
+ else
82
+ @_changed_attributes = attributes
83
+ end
84
+ else
85
+ @_changed_attributes = {}
86
+ end
87
+
88
+ @_parts = {}
89
+ if parts && loaded
90
+ self.class.parts.each_key do |access_name|
91
+ if parts.key?(access_name)
92
+ part = parts[access_name]
93
+ @_parts[access_name] = if part.respond_to?(:to_sid)
94
+ part
95
+ else
96
+ Isomorfeus.instance_from_sid(part)
97
+ end
98
+ end
99
+ end
100
+ elsif loaded
101
+ self.class.parts.each_key do |access_name|
102
+ sid = Redux.fetch_by_path(*(@_parts_path + [access_name]))
103
+ @_parts[access_name] = Isomorfeus.instance_from_sid(sid) if sid
104
+ end
105
+ end
106
+ @_parts.each_value { |part| part.composition = self }
107
+ end
108
+
109
+ def _load_from_store!
110
+ @_changed = false
111
+ @_changed_attributes = {}
112
+ @_parts = {}
113
+ nil
114
+ end
115
+
116
+ def _init_parts
117
+ self.class.parts.each_key do |access_name|
118
+ sid = Redux.fetch_by_path(*(@_parts_path + [access_name]))
119
+ if sid
120
+ @_parts[access_name] = Isomorfeus.instance_from_sid(sid)
121
+ @_parts[access_name].composition = self
122
+ end
123
+ end
124
+ end
125
+
126
+ def parts
127
+ _init_parts if @_parts.empty?
128
+ @_parts
129
+ end
130
+
131
+ def parts_as_sids
132
+ Redux.fetch_by_path(*@_composition_path)
133
+ end
134
+ else # RUBY_ENGINE
135
+ unless base == LucidData::Composition::Base
136
+ Isomorfeus.add_valid_data_class(base)
137
+ base.prop :pub_sub_client, default: nil
138
+ base.prop :current_user, default: Anonymous.new
139
+ end
140
+
141
+ base.instance_exec do
142
+ def load(key:, pub_sub_client: nil, current_user: nil)
143
+ data = instance_exec(key: key, &@_load_block)
144
+ revision = nil
145
+ revision = data.delete(:revision) if data.key?(:revision)
146
+ attributes = data.delete(:attributes)
147
+ parts = data.delete(:parts)
148
+ self.new(key: key, revision: revision, parts: parts, attributes: attributes)
149
+ end
150
+ end
151
+
152
+ def initialize(key:, revision: nil, attributes: nil, parts: nil)
153
+ @key = key.to_s
154
+ @class_name = self.class.name
155
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
156
+ @_revision = revision
157
+ @_changed = false
158
+ @_validate_attributes = self.class.attribute_conditions.any?
159
+ attributes = {} unless attributes
160
+ if @_validate_attributes
161
+ attributes.each { |a,v| _validate_attribute(a, v) }
162
+ end
163
+ @_raw_attributes = attributes
164
+
165
+ @_parts = {}
166
+ self.class.parts.each_key do |access_name|
167
+ if parts.key?(access_name)
168
+ @_parts[access_name] = parts[access_name]
169
+ @_parts[access_name].composition = self
170
+ end
171
+ end
172
+ end
173
+
174
+ def parts
175
+ @_parts
176
+ end
177
+
178
+ def parts_as_sids
179
+ parts.map { |part| part.to_sid }
180
+ end
181
+ end # RUBY_ENGINE
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,15 @@
1
+ module LucidData
2
+ module Document
3
+ class Base
4
+ include LucidData::Node::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
@@ -0,0 +1,9 @@
1
+ module LucidData
2
+ module Document
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(LucidData::Node::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module LucidData
2
+ module Edge
3
+ class Base
4
+ include LucidData::Edge::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
@@ -0,0 +1,281 @@
1
+ module LucidData
2
+ module Edge
3
+ module Mixin
4
+ def self.included(base)
5
+ base.extend(LucidPropDeclaration::Mixin)
6
+ base.include(Isomorfeus::Data::AttributeSupport)
7
+ base.extend(Isomorfeus::Data::GenericClassApi)
8
+ base.include(Isomorfeus::Data::GenericInstanceApi)
9
+
10
+ def changed?
11
+ @_changed
12
+ end
13
+
14
+ def changed!
15
+ @_collection.changed! if @_collection
16
+ @_composition.changed! if @_composition
17
+ @_changed = true
18
+ end
19
+
20
+ def collection
21
+ @_collection
22
+ end
23
+
24
+ def collection=(c)
25
+ @_collection = c
26
+ end
27
+
28
+ def graph
29
+ @_collection&.graph
30
+ end
31
+
32
+ def composition
33
+ @_composition
34
+ end
35
+
36
+ def composition=(c)
37
+ @_composition = c
38
+ end
39
+
40
+ def other(node)
41
+ other_from = from
42
+ other_to = to
43
+ return other_to if other_from == node
44
+ other_from if other_to == node
45
+ end
46
+
47
+ def to_transport
48
+ hash = { "attributes" => _get_selected_attributes,
49
+ "from" => from_as_sid,
50
+ "to" => to_as_sid }
51
+ hash.merge!("revision" => revision) if revision
52
+ { @class_name => { @key => hash }}
53
+ end
54
+
55
+ if RUBY_ENGINE == 'opal'
56
+ def initialize(key:, revision: nil, from: nil, to: nil, attributes: nil, collection: nil, composition: nil)
57
+ @key = key.to_s
58
+ @class_name = self.class.name
59
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
60
+ @_store_path = [:data_state, @class_name, @key, :attributes]
61
+ @_from_path = [:data_state, @class_name, @key, :from]
62
+ @_to_path = [:data_state, @class_name, @key, :to]
63
+ @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
64
+ @_collection = collection
65
+ @_composition = composition
66
+ @_changed = false
67
+ loaded = loaded?
68
+ if attributes
69
+ attributes.each { |a,v| _validate_attribute(a, v) }
70
+ if loaded
71
+ raw_attributes = Redux.fetch_by_path(*@_store_path)
72
+ if `raw_attributes === null`
73
+ @_changed_attributes = !attributes ? {} : attributes
74
+ elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
75
+ @_changed_attributes = attributes
76
+ end
77
+ else
78
+ @_changed_attributes = attributes
79
+ end
80
+ else
81
+ @_changed_attributes = {}
82
+ end
83
+ from = from.to_sid if from.respond_to?(:to_sid)
84
+ if loaded && from
85
+ @_changed_from = nil
86
+ store_from = Redux.fetch_by_path(*@_from_path)
87
+ @_changed_from = from unless `from == store_from`
88
+ else
89
+ @_changed_from = from
90
+ end
91
+ to = to.to_sid if to.respond_to?(:to_sid)
92
+ if loaded && to
93
+ @_changes_to = nil
94
+ store_to = Redux.fetch_by_path(*@_to_path)
95
+ @_changed_to = to unless `to == store_to`
96
+ else
97
+ @_changed_to = to
98
+ end
99
+ end
100
+
101
+ def _load_from_store!
102
+ @_changed_attributes = {}
103
+ @_changed_from = nil
104
+ @_changed_to = nil
105
+ @_changed = false
106
+ end
107
+
108
+ def each(&block)
109
+ _get_attributes.each(&block)
110
+ end
111
+
112
+ def [](name)
113
+ _get_attribute(name)
114
+ end
115
+
116
+ def []=(name, val)
117
+ _validate_attribute(name, val)
118
+ changed!
119
+ @_changed_attributes[name] = val
120
+ end
121
+
122
+ def from
123
+ sid = from_as_sid
124
+ Isomorfeus.instance_from_sid(sid) if sid
125
+ end
126
+
127
+ def from_as_sid
128
+ @_changed_from ? @_changed_from : Redux.fetch_by_path(*@_from_path)
129
+ end
130
+
131
+ def from=(document)
132
+ changed!
133
+ if document.respond_to?(:to_sid)
134
+ @_changed_from = document.to_sid
135
+ document
136
+ else
137
+ @_changed_from = document
138
+ Isomorfeus.instance_from_sid(document)
139
+ end
140
+ end
141
+
142
+ def to
143
+ sid = to_as_sid
144
+ Isomorfeus.instance_from_sid(sid) if sid
145
+ end
146
+
147
+ def to_as_sid
148
+ @_changed_to ? @_changed_to : Redux.fetch_by_path(*@_to_path)
149
+ end
150
+
151
+ def to=(document)
152
+ changed!
153
+ if document.respond_to?(:to_sid)
154
+ @_changed_to = document.to_sid
155
+ document
156
+ else
157
+ @_changed_to = document
158
+ Isomorfeus.instance_from_sid(document)
159
+ end
160
+ end
161
+ else # RUBY_ENGINE
162
+ unless base == LucidData::Edge::Base || base == LucidData::Link::Base
163
+ Isomorfeus.add_valid_data_class(base)
164
+ base.prop :pub_sub_client, default: nil
165
+ base.prop :current_user, default: Anonymous.new
166
+ end
167
+
168
+ base.instance_exec do
169
+ def load(key:, pub_sub_client: nil, current_user: nil)
170
+ data = instance_exec(key: key, &@_load_block)
171
+ revision = nil
172
+ revision = data.delete(:revision) if data.key?(:revision)
173
+ from = nil
174
+ from = data.delete(:_from) if data.key?(:_from)
175
+ from = data.delete(:from) if !from && data.key?(:from)
176
+ to = nil
177
+ to = data.delete(:_to) if data.key?(:_to)
178
+ to = data.delete(:to) if !to&& data.key?(:to)
179
+ attributes = data.delete(:attributes)
180
+ self.new(key: key, revision: revision, from: from, to: to, attributes: attributes)
181
+ end
182
+ end
183
+
184
+ def initialize(key:, revision: nil, from:, to:, attributes: nil, collection: nil, composition: nil)
185
+ @key = key.to_s
186
+ @class_name = self.class.name
187
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
188
+ @_revision = revision
189
+ @_composition = composition
190
+ @_changed = false
191
+ @_collection = collection
192
+ @_validate_attributes = self.class.attribute_conditions.any?
193
+ attributes = {} unless attributes
194
+ if @_validate_attributes
195
+ attributes.each { |a,v| _validate_attribute(a, v) }
196
+ end
197
+ @_raw_attributes = attributes
198
+ @_changed_from = nil
199
+ @_changed_to = nil
200
+ @_raw_from = if from.respond_to?(:to_sid)
201
+ from.to_sid
202
+ else
203
+ from[1] = from[1].to_s
204
+ from
205
+ end
206
+ @_raw_to = if to.respond_to?(:to_sid)
207
+ to.to_sid
208
+ else
209
+ to[1] = to[1].to_s
210
+ to
211
+ end
212
+ end
213
+
214
+ def each(&block)
215
+ @_raw_attributes.each(&block)
216
+ end
217
+
218
+ def [](name)
219
+ @_raw_attributes[name]
220
+ end
221
+
222
+ def []=(name, val)
223
+ _validate_attribute(name, val)
224
+ changed!
225
+ @_raw_attributes[name] = val
226
+ end
227
+
228
+ def from
229
+ sid = @_changed_from ? @_changed_from : @_raw_from
230
+ graph&.node_from_sid(sid)
231
+ end
232
+
233
+ def from_as_sid
234
+ @_changed_from ? @_changed_from : @_raw_from
235
+ end
236
+
237
+ def from=(node)
238
+ raise "A invalid 'from' was given" unless node
239
+ changed!
240
+ old_from = from
241
+ if node.respond_to?(:to_sid)
242
+ node_sid = node.to_sid
243
+ else
244
+ node_sid = node
245
+ node_sid[1] = node_sid[1].to_s
246
+ node = graph.node_from_sid(node_sid)
247
+ end
248
+ @_changed_from = node_sid
249
+ @_collection.update_node_to_edge_cache(self, old_from, node) if @_collection
250
+ node
251
+ end
252
+
253
+ def to
254
+ sid = @_changed_to ? @_changed_to : @_raw_to
255
+ graph&.node_from_sid(sid)
256
+ end
257
+
258
+ def to_as_sid
259
+ @_changed_to ? @_changed_to : @_raw_to
260
+ end
261
+
262
+ def to=(node)
263
+ raise "A invalid 'to' was given" unless node
264
+ old_to = to
265
+ changed!
266
+ if node.respond_to?(:to_sid)
267
+ node_sid = node.to_sid
268
+ else
269
+ node_sid = node
270
+ node_sid[1] = node_sid[1].to_s
271
+ node = graph.node_from_sid(node_sid)
272
+ end
273
+ @_changed_to = node_sid
274
+ @_collection.update_node_to_edge_cache(self, old_to, node) if @_collection
275
+ node
276
+ end
277
+ end # RUBY_ENGINE
278
+ end
279
+ end
280
+ end
281
+ end
@@ -0,0 +1,15 @@
1
+ module LucidData
2
+ module EdgeCollection
3
+ class Base
4
+ include LucidData::EdgeCollection::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
@@ -0,0 +1,134 @@
1
+ module LucidData
2
+ module EdgeCollection
3
+ module Finders
4
+ def find(attribute_hash = nil, &block)
5
+ if block_given?
6
+ edges.each do |edge|
7
+ return edge if block.call(edge)
8
+ end
9
+ else
10
+ edge_class = attribute_hash.delete(:class)
11
+ is_a_module = attribute_hash.delete(:is_a)
12
+ edges.each do |edge|
13
+ if edge_class
14
+ next unless edge.class == edge_class
15
+ end
16
+ if is_a_module
17
+ next unless edge.is_a?(is_a_module)
18
+ end
19
+ found = true
20
+ attribute_hash.each do |k,v|
21
+ found &&= (edge[k] == v)
22
+ break unless found
23
+ end
24
+ return edge if found
25
+ end
26
+ end
27
+ nil
28
+ end
29
+
30
+ def find_all(attribute_hash = nil, &block)
31
+ found_edges = Set.new
32
+ if block_given?
33
+ edges.each do |edge|
34
+ found_edges << edge if block.call(edge)
35
+ end
36
+ else
37
+ edge_class = attribute_hash.delete(:class)
38
+ is_a_module = attribute_hash.delete(:is_a)
39
+ edges.each do |edge|
40
+ if edge_class
41
+ next unless edge.class == edge_class
42
+ end
43
+ if is_a_module
44
+ next unless edge.is_a?(is_a_module)
45
+ end
46
+ found = true
47
+ attribute_hash.each do |k,v|
48
+ found &&= (edge[k] == v)
49
+ break unless found
50
+ end
51
+ found_edges << edge if found
52
+ end
53
+ end
54
+ found_edges
55
+ end
56
+
57
+ def find_by_key(edge_key)
58
+ edges.each do |edge|
59
+ return edge if edge.key == edge_key
60
+ end
61
+ nil
62
+ end
63
+
64
+ if RUBY_ENGINE == 'opal'
65
+ def find_by_sid(edge)
66
+ edge_sid = edge.respond_to?(:to_sid) ? edge.to_sid : edge
67
+ edges_as_sids.each do |sid|
68
+ return Isomorfeus.instance_from_sid(edge_sid) if sid == edge_sid
69
+ end
70
+ nil
71
+ end
72
+ else
73
+ def find_by_sid(edge)
74
+ edge_sid = edge.respond_to?(:to_sid) ? edge.to_sid : edge
75
+ edges.each do |edge|
76
+ return edge if edge.to_sid == edge_sid
77
+ end
78
+ nil
79
+ end
80
+ end
81
+
82
+ def find_by_from(node)
83
+ node_sid = node.respond_to?(:to_sid) ? node.to_sid : node
84
+ edges.each do |edge|
85
+ return edge if edge.from_as_sid == node_sid
86
+ end
87
+ nil
88
+ end
89
+
90
+ def find_all_by_from(node)
91
+ node_sid = node.respond_to?(:to_sid) ? node.to_sid : node
92
+ found_edges = []
93
+ edges.each do |edge|
94
+ found_edges << edge if edge.from_as_sid == node_sid
95
+ end
96
+ found_edges
97
+ end
98
+
99
+ def find_by_to(node)
100
+ node_sid = node.respond_to?(:to_sid) ? node.to_sid : node
101
+ edges.each do |edge|
102
+ return edge if edge.to_as_sid == node_sid
103
+ end
104
+ nil
105
+ end
106
+
107
+ def find_all_by_to(node)
108
+ node_sid = node.respond_to?(:to_sid) ? node.to_sid : node
109
+ found_edges = []
110
+ edges.each do |edge|
111
+ found_edges << edge if edge.to_as_sid == node_sid
112
+ end
113
+ found_edges
114
+ end
115
+
116
+ def find_by_target(node)
117
+ node_sid = node.respond_to?(:to_sid) ? node.to_sid : node
118
+ edges.each do |edge|
119
+ return edge if edge.from_as_sid == node_sid || edge.to_as_sid == node_sid
120
+ end
121
+ nil
122
+ end
123
+
124
+ def find_all_by_target(node)
125
+ node_sid = node.respond_to?(:to_sid) ? node.to_sid : node
126
+ found_edges = []
127
+ edges.each do |edge|
128
+ found_edges << edge if edge.from_as_sid == node_sid || edge.to_as_sid == node_sid
129
+ end
130
+ found_edges
131
+ end
132
+ end
133
+ end
134
+ end