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.
- checksums.yaml +4 -4
- data/LICENSE +47 -21
- data/README.md +38 -46
- data/lib/isomorfeus/data/attribute_support.rb +176 -176
- data/lib/isomorfeus/data/config.rb +79 -110
- data/lib/isomorfeus/data/element_validator.rb +147 -147
- data/lib/isomorfeus/data/ferret_accelerator.rb +66 -0
- data/lib/isomorfeus/data/field_support.rb +110 -0
- data/lib/isomorfeus/data/generic_class_api.rb +136 -116
- data/lib/isomorfeus/data/generic_instance_api.rb +150 -145
- data/lib/isomorfeus/data/hamster_accelerator.rb +87 -0
- data/lib/isomorfeus/data/hamster_storage_expander.rb +94 -0
- data/lib/isomorfeus/data/handler/generic.rb +134 -138
- data/lib/isomorfeus/data/reducer.rb +30 -30
- data/lib/isomorfeus/data/version.rb +4 -4
- data/lib/isomorfeus-data.rb +56 -64
- data/lib/isomorfeus_data/lucid_document/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_document/mixin.rb +148 -0
- data/lib/isomorfeus_data/lucid_file/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_file/mixin.rb +217 -0
- data/lib/isomorfeus_data/lucid_object/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_object/mixin.rb +216 -0
- data/lib/isomorfeus_data/lucid_query/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_query/mixin.rb +81 -0
- data/lib/isomorfeus_data/lucid_query_result.rb +97 -0
- data/opal/uri/common.rb +18 -0
- data/opal/uri/generic.rb +47 -0
- data/opal/uri.rb +29 -0
- metadata +85 -96
- data/lib/isomorfeus/data/handler/arango.rb +0 -56
- data/lib/isomorfeus/data/handler/object_call.rb +0 -40
- data/lib/isomorfeus/data/handler/object_store.rb +0 -40
- data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/array/mixin.rb +0 -580
- data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/collection/finders.rb +0 -83
- data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +0 -737
- data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +0 -234
- data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/document/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +0 -286
- data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +0 -134
- data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +0 -747
- data/lib/isomorfeus_data/lucid_data/generic_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_node.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/graph/finders.rb +0 -141
- data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +0 -489
- data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +0 -427
- data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/node/mixin.rb +0 -232
- data/lib/isomorfeus_data/lucid_data/query/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/query/mixin.rb +0 -83
- data/lib/isomorfeus_data/lucid_data/query_result.rb +0 -95
- data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +0 -9
- data/lib/lucid_arango/collection/base.rb +0 -13
- data/lib/lucid_arango/collection/mixin.rb +0 -18
- data/lib/lucid_arango/document/base.rb +0 -13
- data/lib/lucid_arango/document/mixin.rb +0 -9
- data/lib/lucid_arango/edge/base.rb +0 -13
- data/lib/lucid_arango/edge/mixin.rb +0 -18
- data/lib/lucid_arango/edge_collection/base.rb +0 -13
- data/lib/lucid_arango/edge_collection/mixin.rb +0 -18
- data/lib/lucid_arango/graph/base.rb +0 -13
- data/lib/lucid_arango/graph/mixin.rb +0 -18
- data/lib/lucid_arango/node/base.rb +0 -13
- data/lib/lucid_arango/node/mixin.rb +0 -79
- data/lib/lucid_arango/object/base.rb +0 -11
- data/lib/lucid_arango/object/mixin.rb +0 -158
- data/lib/lucid_arango/remote_object/base.rb +0 -11
- data/lib/lucid_arango/remote_object/mixin.rb +0 -17
- data/lib/lucid_arango/vertex/base.rb +0 -13
- data/lib/lucid_arango/vertex/mixin.rb +0 -9
@@ -1,234 +0,0 @@
|
|
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.include(Isomorfeus::Data::AttributeSupport)
|
9
|
-
base.extend(Isomorfeus::Data::GenericClassApi)
|
10
|
-
base.include(Isomorfeus::Data::GenericInstanceApi)
|
11
|
-
|
12
|
-
base.instance_exec do
|
13
|
-
def parts
|
14
|
-
@parts ||= {}
|
15
|
-
end
|
16
|
-
|
17
|
-
def compose_with(access_name, validate_hash = {})
|
18
|
-
parts[access_name] = validate_hash
|
19
|
-
|
20
|
-
define_method(access_name) do
|
21
|
-
parts[access_name]
|
22
|
-
end
|
23
|
-
|
24
|
-
define_method("#{access_name}=") do |part|
|
25
|
-
part_conditions = self.class.parts[access_name]
|
26
|
-
Isomorfeus::Data::ElementValidator.new(self.name, part, part_conditions).validate!
|
27
|
-
@_changed = true
|
28
|
-
parts[access_name] = part
|
29
|
-
parts[access_name].composition = self
|
30
|
-
parts[access_name]
|
31
|
-
end
|
32
|
-
|
33
|
-
define_singleton_method("valid_#{access_name}?") do |part|
|
34
|
-
_validate(access_name, part)
|
35
|
-
rescue
|
36
|
-
false
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def _validate_part(access_name, part)
|
41
|
-
Isomorfeus.raise_error(message: "#{self.name}: No such part declared: '#{access_name}'!") unless parts.key?(access_name)
|
42
|
-
Isomorfeus::Data::ElementValidator.new(self.name, part, parts[access_name]).validate!
|
43
|
-
end
|
44
|
-
|
45
|
-
def _validate_parts(many_parts)
|
46
|
-
parts.each_key do |access_name|
|
47
|
-
if parts[access_name].key?(:required) && parts[access_name][:required] && !many_parts.key?(attr)
|
48
|
-
Isomorfeus.raise_error(message: "Required part #{access_name} not given!")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
many_parts.each { |access_name, part| _validate_part(access_name, part) } if parts.any?
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def _validate_part(access_name, part)
|
56
|
-
self.class._validate_part(access_name, part)
|
57
|
-
end
|
58
|
-
|
59
|
-
def _validate_parts(many_parts)
|
60
|
-
self.class._validate_parts(many_parts)
|
61
|
-
end
|
62
|
-
|
63
|
-
def changed?
|
64
|
-
@_changed
|
65
|
-
end
|
66
|
-
|
67
|
-
def changed!
|
68
|
-
@_changed = true
|
69
|
-
end
|
70
|
-
|
71
|
-
def to_transport
|
72
|
-
hash = { 'attributes' => _get_selected_attributes, 'parts' => {} }
|
73
|
-
hash.merge!('revision' => revision) if revision
|
74
|
-
parts.each do |name, instance|
|
75
|
-
hash['parts'][name.to_s] = instance.to_sid if instance
|
76
|
-
end
|
77
|
-
result = { @class_name => { @key => hash }}
|
78
|
-
result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
|
79
|
-
result
|
80
|
-
end
|
81
|
-
|
82
|
-
def included_items_to_transport
|
83
|
-
hash = {}
|
84
|
-
parts.each_value do |instance|
|
85
|
-
if instance
|
86
|
-
hash.deep_merge!(instance.to_transport)
|
87
|
-
hash.deep_merge!(instance.included_items_to_transport) if instance.respond_to?(:included_items_to_transport)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
hash
|
91
|
-
end
|
92
|
-
|
93
|
-
if RUBY_ENGINE == 'opal'
|
94
|
-
def initialize(key:, revision: nil, attributes: nil, parts: nil)
|
95
|
-
@key = key.to_s
|
96
|
-
@class_name = self.class.name
|
97
|
-
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
98
|
-
_update_paths
|
99
|
-
@_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
|
100
|
-
@_changed = false
|
101
|
-
|
102
|
-
loaded = loaded?
|
103
|
-
|
104
|
-
if attributes
|
105
|
-
_validate_attributes(attributes)
|
106
|
-
if loaded
|
107
|
-
raw_attributes = Redux.fetch_by_path(*@_store_path)
|
108
|
-
if `raw_attributes === null`
|
109
|
-
@_changed_attributes = !attributes ? {} : attributes
|
110
|
-
elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
|
111
|
-
@_changed_attributes = attributes
|
112
|
-
end
|
113
|
-
else
|
114
|
-
@_changed_attributes = attributes
|
115
|
-
end
|
116
|
-
else
|
117
|
-
@_changed_attributes = {}
|
118
|
-
end
|
119
|
-
|
120
|
-
@_parts = {}
|
121
|
-
if parts && loaded
|
122
|
-
_validate_parts(parts)
|
123
|
-
self.class.parts.each_key do |access_name|
|
124
|
-
if parts.key?(access_name)
|
125
|
-
part = parts[access_name]
|
126
|
-
@_parts[access_name] = if part.respond_to?(:to_sid)
|
127
|
-
part
|
128
|
-
else
|
129
|
-
Isomorfeus.instance_from_sid(part)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
elsif loaded
|
134
|
-
self.class.parts.each_key do |access_name|
|
135
|
-
sid = Redux.fetch_by_path(*(@_parts_path + [access_name]))
|
136
|
-
@_parts[access_name] = Isomorfeus.instance_from_sid(sid) if sid
|
137
|
-
end
|
138
|
-
end
|
139
|
-
@_parts.each_value { |part| part.composition = self }
|
140
|
-
end
|
141
|
-
|
142
|
-
def _load_from_store!
|
143
|
-
@_changed = false
|
144
|
-
@_changed_attributes = {}
|
145
|
-
@_parts = {}
|
146
|
-
nil
|
147
|
-
end
|
148
|
-
|
149
|
-
def _update_paths
|
150
|
-
@_store_path = [:data_state, @class_name, @key, :attributes]
|
151
|
-
@_parts_path = [:data_state, @class_name, @key, :parts]
|
152
|
-
end
|
153
|
-
|
154
|
-
def _init_parts
|
155
|
-
self.class.parts.each_key do |access_name|
|
156
|
-
sid = Redux.fetch_by_path(*(@_parts_path + [access_name]))
|
157
|
-
if sid
|
158
|
-
@_parts[access_name] = Isomorfeus.instance_from_sid(sid)
|
159
|
-
@_parts[access_name].composition = self
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def parts
|
165
|
-
_init_parts if @_parts.empty?
|
166
|
-
@_parts
|
167
|
-
end
|
168
|
-
|
169
|
-
def parts_as_sids
|
170
|
-
Redux.fetch_by_path(*@_composition_path)
|
171
|
-
end
|
172
|
-
else # RUBY_ENGINE
|
173
|
-
Isomorfeus.add_valid_data_class(base) unless base == LucidData::Composition::Base
|
174
|
-
|
175
|
-
base.instance_exec do
|
176
|
-
def instance_from_transport(instance_data, included_items_data)
|
177
|
-
key = instance_data[self.name].keys.first
|
178
|
-
revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
|
179
|
-
attributes = instance_data[self.name][key].key?('attributes') ? instance_data[self.name][key]['attributes'].transform_keys!(&:to_sym) : nil
|
180
|
-
source_parts = instance_data[self.name][key].key?('parts') ? instance_data[self.name][key]['parts'] : {}
|
181
|
-
parts = {}
|
182
|
-
source_parts.each do |part_name, sid|
|
183
|
-
part_class_name = sid[0]
|
184
|
-
part_key = sid[1]
|
185
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{part_class_name}: Not a valid LucidData class!") unless Isomorfeus.valid_data_class_name?(part_class_name)
|
186
|
-
if included_items_data.key?(part_class_name) && included_items_data[part_class_name].key?(part_key)
|
187
|
-
part_class = Isomorfeus.cached_data_class(part_class_name)
|
188
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{part_class_name}: Cannot get class!") unless part_class
|
189
|
-
part = part_class.instance_from_transport({ part_class_name => { part_key => included_items_data[part_class_name][part_key] }}, included_items_data)
|
190
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{part_class_name} with key #{part_key} could not be extracted from transport data!") unless part
|
191
|
-
parts[part_name.to_sym] = part
|
192
|
-
end
|
193
|
-
end
|
194
|
-
new(key: key, revision: revision, attributes: attributes, parts: parts)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def initialize(key:, revision: nil, attributes: nil, parts: nil)
|
199
|
-
@key = key.to_s
|
200
|
-
@class_name = self.class.name
|
201
|
-
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
202
|
-
@_revision = revision
|
203
|
-
@_changed = false
|
204
|
-
@_validate_attributes = self.class.attribute_conditions.any?
|
205
|
-
attributes = {} unless attributes
|
206
|
-
_validate_attributes(attributes) if attributes.any?
|
207
|
-
@_raw_attributes = attributes
|
208
|
-
|
209
|
-
@_parts = {}
|
210
|
-
_validate_parts(parts)
|
211
|
-
self.class.parts.each_key do |access_name|
|
212
|
-
if parts.key?(access_name)
|
213
|
-
@_parts[access_name] = parts[access_name]
|
214
|
-
@_parts[access_name].composition = self
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
def _unchange!
|
220
|
-
@_changed = false
|
221
|
-
end
|
222
|
-
|
223
|
-
def parts
|
224
|
-
@_parts
|
225
|
-
end
|
226
|
-
|
227
|
-
def parts_as_sids
|
228
|
-
parts.map { |part| part.to_sid }
|
229
|
-
end
|
230
|
-
end # RUBY_ENGINE
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
@@ -1,286 +0,0 @@
|
|
1
|
-
module LucidData
|
2
|
-
module Edge
|
3
|
-
module Mixin
|
4
|
-
def self.included(base)
|
5
|
-
base.include(Isomorfeus::Data::AttributeSupport)
|
6
|
-
base.extend(Isomorfeus::Data::GenericClassApi)
|
7
|
-
base.include(Isomorfeus::Data::GenericInstanceApi)
|
8
|
-
|
9
|
-
def changed?
|
10
|
-
@_changed
|
11
|
-
end
|
12
|
-
|
13
|
-
def changed!
|
14
|
-
@_collection.changed! if @_collection
|
15
|
-
@_composition.changed! if @_composition
|
16
|
-
@_changed = true
|
17
|
-
end
|
18
|
-
|
19
|
-
def collection
|
20
|
-
@_collection
|
21
|
-
end
|
22
|
-
|
23
|
-
def collection=(c)
|
24
|
-
@_collection = c
|
25
|
-
end
|
26
|
-
|
27
|
-
def graph
|
28
|
-
@_collection&.graph
|
29
|
-
end
|
30
|
-
|
31
|
-
def composition
|
32
|
-
@_composition
|
33
|
-
end
|
34
|
-
|
35
|
-
def composition=(c)
|
36
|
-
@_composition = c
|
37
|
-
end
|
38
|
-
|
39
|
-
def other(node)
|
40
|
-
other_from = from
|
41
|
-
other_to = to
|
42
|
-
return other_to if other_from == node
|
43
|
-
other_from if other_to == node
|
44
|
-
end
|
45
|
-
|
46
|
-
def from
|
47
|
-
graph&.node_from_sid(from_as_sid)
|
48
|
-
end
|
49
|
-
|
50
|
-
def to
|
51
|
-
graph&.node_from_sid(to_as_sid)
|
52
|
-
end
|
53
|
-
|
54
|
-
def to_transport
|
55
|
-
hash = { "attributes" => _get_selected_attributes,
|
56
|
-
"from" => from_as_sid,
|
57
|
-
"to" => to_as_sid }
|
58
|
-
hash.merge!("revision" => revision) if revision
|
59
|
-
result = { @class_name => { @key => hash }}
|
60
|
-
result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
|
61
|
-
result
|
62
|
-
end
|
63
|
-
|
64
|
-
if RUBY_ENGINE == 'opal'
|
65
|
-
def initialize(key:, revision: nil, from: nil, to: nil, attributes: nil, collection: nil, composition: nil)
|
66
|
-
@key = key.to_s
|
67
|
-
@class_name = self.class.name
|
68
|
-
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
69
|
-
_update_paths
|
70
|
-
@_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
|
71
|
-
@_collection = collection
|
72
|
-
@_composition = composition
|
73
|
-
@_changed = false
|
74
|
-
loaded = loaded?
|
75
|
-
if attributes
|
76
|
-
_validate_attributes(attributes)
|
77
|
-
if loaded
|
78
|
-
raw_attributes = Redux.fetch_by_path(*@_store_path)
|
79
|
-
if `raw_attributes === null`
|
80
|
-
@_changed_attributes = !attributes ? {} : attributes
|
81
|
-
elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
|
82
|
-
@_changed_attributes = attributes
|
83
|
-
end
|
84
|
-
else
|
85
|
-
@_changed_attributes = attributes
|
86
|
-
end
|
87
|
-
else
|
88
|
-
@_changed_attributes = {}
|
89
|
-
end
|
90
|
-
from = from.to_sid if from.respond_to?(:to_sid)
|
91
|
-
if loaded && from
|
92
|
-
@_changed_from = nil
|
93
|
-
store_from = Redux.fetch_by_path(*@_from_path)
|
94
|
-
@_changed_from = from unless `from == store_from`
|
95
|
-
else
|
96
|
-
@_changed_from = from
|
97
|
-
end
|
98
|
-
to = to.to_sid if to.respond_to?(:to_sid)
|
99
|
-
if loaded && to
|
100
|
-
@_changes_to = nil
|
101
|
-
store_to = Redux.fetch_by_path(*@_to_path)
|
102
|
-
@_changed_to = to unless `to == store_to`
|
103
|
-
else
|
104
|
-
@_changed_to = to
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def _load_from_store!
|
109
|
-
@_changed_attributes = {}
|
110
|
-
@_changed_from = nil
|
111
|
-
@_changed_to = nil
|
112
|
-
@_changed = false
|
113
|
-
end
|
114
|
-
|
115
|
-
def _update_paths
|
116
|
-
@_store_path = [:data_state, @class_name, @key, :attributes]
|
117
|
-
@_from_path = [:data_state, @class_name, @key, :from]
|
118
|
-
@_to_path = [:data_state, @class_name, @key, :to]
|
119
|
-
end
|
120
|
-
|
121
|
-
def each(&block)
|
122
|
-
attributes.each(&block)
|
123
|
-
end
|
124
|
-
|
125
|
-
def [](name)
|
126
|
-
_get_attribute(name)
|
127
|
-
end
|
128
|
-
|
129
|
-
def []=(name, val)
|
130
|
-
_validate_attribute(name, val)
|
131
|
-
changed!
|
132
|
-
@_changed_attributes[name] = val
|
133
|
-
end
|
134
|
-
|
135
|
-
def from_as_sid
|
136
|
-
@_changed_from ? @_changed_from : Redux.fetch_by_path(*@_from_path)
|
137
|
-
end
|
138
|
-
|
139
|
-
def from=(node)
|
140
|
-
changed!
|
141
|
-
old_from = from
|
142
|
-
if node.respond_to?(:to_sid)
|
143
|
-
@_changed_from = node.to_sid
|
144
|
-
else
|
145
|
-
@_changed_from = node
|
146
|
-
node = Isomorfeus.instance_from_sid(node)
|
147
|
-
end
|
148
|
-
@_collection.update_node_to_edge_cache(self, old_from, node) if @_collection
|
149
|
-
node
|
150
|
-
end
|
151
|
-
|
152
|
-
def to_as_sid
|
153
|
-
@_changed_to ? @_changed_to : Redux.fetch_by_path(*@_to_path)
|
154
|
-
end
|
155
|
-
|
156
|
-
def to=(node)
|
157
|
-
changed!
|
158
|
-
old_to = to
|
159
|
-
if node.respond_to?(:to_sid)
|
160
|
-
@_changed_to = node.to_sid
|
161
|
-
node
|
162
|
-
else
|
163
|
-
@_changed_to = node
|
164
|
-
node = Isomorfeus.instance_from_sid(node)
|
165
|
-
end
|
166
|
-
@_collection.update_node_to_edge_cache(self, old_to, node) if @_collection
|
167
|
-
node
|
168
|
-
end
|
169
|
-
else # RUBY_ENGINE
|
170
|
-
Isomorfeus.add_valid_data_class(base) unless base == LucidData::Edge::Base || base == LucidData::Link::Base
|
171
|
-
|
172
|
-
base.instance_exec do
|
173
|
-
def instance_from_transport(instance_data, included_items_data)
|
174
|
-
key = instance_data[self.name].keys.first
|
175
|
-
revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
|
176
|
-
attributes = instance_data[self.name][key].key?('attributes') ? instance_data[self.name][key]['attributes'].transform_keys!(&:to_sym) : nil
|
177
|
-
from_node_sid = instance_data[self.name][key].key?('from') ? instance_data[self.name][key]['from'] : nil
|
178
|
-
to_node_sid = instance_data[self.name][key].key?('to') ? instance_data[self.name][key]['to'] : nil
|
179
|
-
from_to = []
|
180
|
-
if from_node_sid && to_node_sid
|
181
|
-
[from_node_sid, to_node_sid].each do |sid|
|
182
|
-
node_class_name = sid[0]
|
183
|
-
node_key = sid[1]
|
184
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Not a valid LucidData class!") unless Isomorfeus.valid_data_class_name?(node_class_name)
|
185
|
-
if included_items_data.key?(node_class_name) && included_items_data[node_class_name].key?(node_key)
|
186
|
-
node_class = Isomorfeus.cached_data_class(node_class_name)
|
187
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Cannot get class!") unless node_class
|
188
|
-
node = node_class.instance_from_transport({ node_class_name => { node_key => included_items_data[node_class_name][node_key] }}, included_items_data)
|
189
|
-
Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name} with key #{node_key} could not be extracted from transport data!") unless node
|
190
|
-
from_to << node
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
new(key: key, revision: revision, attributes: attributes, from: from_to[0], to: from_to[1])
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def initialize(key:, revision: nil, from:, to:, attributes: nil, collection: nil, composition: nil)
|
199
|
-
@key = key.to_s
|
200
|
-
@class_name = self.class.name
|
201
|
-
@class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
|
202
|
-
@_revision = revision
|
203
|
-
@_composition = composition
|
204
|
-
@_changed = false
|
205
|
-
@_collection = collection
|
206
|
-
attributes = {} unless attributes
|
207
|
-
_validate_attributes(attributes) if attributes
|
208
|
-
@_raw_attributes = attributes
|
209
|
-
@_changed_from = nil
|
210
|
-
@_changed_to = nil
|
211
|
-
@_raw_from = if from.respond_to?(:to_sid)
|
212
|
-
from.to_sid
|
213
|
-
else
|
214
|
-
from[1] = from[1].to_s
|
215
|
-
from
|
216
|
-
end
|
217
|
-
@_raw_to = if to.respond_to?(:to_sid)
|
218
|
-
to.to_sid
|
219
|
-
else
|
220
|
-
to[1] = to[1].to_s
|
221
|
-
to
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def _unchange!
|
226
|
-
@_changed =false
|
227
|
-
end
|
228
|
-
|
229
|
-
def each(&block)
|
230
|
-
@_raw_attributes.each(&block)
|
231
|
-
end
|
232
|
-
|
233
|
-
def [](name)
|
234
|
-
@_raw_attributes[name]
|
235
|
-
end
|
236
|
-
|
237
|
-
def []=(name, val)
|
238
|
-
_validate_attribute(name, val)
|
239
|
-
changed!
|
240
|
-
@_raw_attributes[name] = val
|
241
|
-
end
|
242
|
-
|
243
|
-
def from_as_sid
|
244
|
-
@_changed_from ? @_changed_from : @_raw_from
|
245
|
-
end
|
246
|
-
|
247
|
-
def from=(node)
|
248
|
-
Isomorfeus.raise_error(message: "A invalid 'from' was given") unless node
|
249
|
-
changed!
|
250
|
-
old_from = from
|
251
|
-
if node.respond_to?(:to_sid)
|
252
|
-
node_sid = node.to_sid
|
253
|
-
else
|
254
|
-
node_sid = node
|
255
|
-
node_sid[1] = node_sid[1].to_s
|
256
|
-
node = graph.node_from_sid(node_sid)
|
257
|
-
end
|
258
|
-
@_changed_from = node_sid
|
259
|
-
@_collection.update_node_to_edge_cache(self, old_from, node) if @_collection
|
260
|
-
node
|
261
|
-
end
|
262
|
-
|
263
|
-
def to_as_sid
|
264
|
-
@_changed_to ? @_changed_to : @_raw_to
|
265
|
-
end
|
266
|
-
|
267
|
-
def to=(node)
|
268
|
-
Isomorfeus.raise_error(message: "A invalid 'to' was given") unless node
|
269
|
-
old_to = to
|
270
|
-
changed!
|
271
|
-
if node.respond_to?(:to_sid)
|
272
|
-
node_sid = node.to_sid
|
273
|
-
else
|
274
|
-
node_sid = node
|
275
|
-
node_sid[1] = node_sid[1].to_s
|
276
|
-
node = graph.node_from_sid(node_sid)
|
277
|
-
end
|
278
|
-
@_changed_to = node_sid
|
279
|
-
@_collection.update_node_to_edge_cache(self, old_to, node) if @_collection
|
280
|
-
node
|
281
|
-
end
|
282
|
-
end # RUBY_ENGINE
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|