isomorfeus-data 1.0.0.zeta12 → 1.0.0.zeta13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -0
  3. data/lib/isomorfeus-data.rb +2 -0
  4. data/lib/isomorfeus/data/attribute_support.rb +2 -2
  5. data/lib/isomorfeus/data/config.rb +1 -1
  6. data/lib/isomorfeus/data/element_validator.rb +16 -16
  7. data/lib/isomorfeus/data/generic_class_api.rb +34 -52
  8. data/lib/isomorfeus/data/generic_instance_api.rb +35 -8
  9. data/lib/isomorfeus/data/handler/arango.rb +2 -3
  10. data/lib/isomorfeus/data/handler/generic.rb +44 -55
  11. data/lib/isomorfeus/data/handler/object_call.rb +2 -3
  12. data/lib/isomorfeus/data/handler/object_store.rb +2 -3
  13. data/lib/isomorfeus/data/version.rb +1 -1
  14. data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -2
  15. data/lib/isomorfeus_data/lucid_data/array/mixin.rb +18 -22
  16. data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -2
  17. data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +33 -36
  18. data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -2
  19. data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +35 -29
  20. data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -2
  21. data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -2
  22. data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +39 -31
  23. data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -2
  24. data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +33 -29
  25. data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -2
  26. data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +41 -40
  27. data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -2
  28. data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +20 -25
  29. data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -2
  30. data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -2
  31. data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -2
  32. data/lib/isomorfeus_data/lucid_data/node/mixin.rb +18 -23
  33. data/lib/isomorfeus_data/lucid_data/query/base.rb +13 -0
  34. data/lib/isomorfeus_data/lucid_data/query/mixin.rb +88 -0
  35. data/lib/isomorfeus_data/lucid_data/query_result.rb +12 -10
  36. data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -2
  37. data/lib/lucid_arango/collection/base.rb +0 -2
  38. data/lib/lucid_arango/collection/mixin.rb +0 -2
  39. data/lib/lucid_arango/document/base.rb +0 -2
  40. data/lib/lucid_arango/edge/base.rb +0 -3
  41. data/lib/lucid_arango/edge/mixin.rb +0 -2
  42. data/lib/lucid_arango/edge_collection/base.rb +0 -2
  43. data/lib/lucid_arango/edge_collection/mixin.rb +0 -2
  44. data/lib/lucid_arango/graph/base.rb +0 -2
  45. data/lib/lucid_arango/graph/mixin.rb +0 -2
  46. data/lib/lucid_arango/node/base.rb +0 -3
  47. data/lib/lucid_arango/node/mixin.rb +0 -2
  48. data/lib/lucid_arango/object/base.rb +0 -2
  49. data/lib/lucid_arango/object/mixin.rb +1 -3
  50. data/lib/lucid_arango/remote_object/base.rb +0 -2
  51. data/lib/lucid_arango/remote_object/mixin.rb +0 -2
  52. data/lib/lucid_arango/vertex/base.rb +0 -2
  53. metadata +10 -8
@@ -4,7 +4,7 @@ module Isomorfeus
4
4
  module Data
5
5
  module Handler
6
6
  class Object < LucidHandler::Base
7
- on_request do |pub_sub_client, current_user, response_agent|
7
+ on_request do |response_agent|
8
8
  # promise_send_path('Isomorfeus::Data::Handler::Object', action, object_hash)
9
9
  response_agent.request.each_key do |array_class_name|
10
10
  if Isomorfeus.valid_array_class_name?(array_class_name)
@@ -13,11 +13,10 @@ module Isomorfeus
13
13
  props_json = response_agent.request[array_class_name]
14
14
  begin
15
15
  props = Oj.load(props_json, mode: :strict)
16
- props.merge!({pub_sub_client: pub_sub_client, current_user: current_user})
17
16
  if current_user.authorized?(array_class, :load, *props)
18
17
  array = array_class.load(props)
19
18
  array.instance_exec do
20
- array_class.on_load_block.call(pub_sub_client, current_user) if array_class.on_load_block
19
+ array_class.on_load_block.call() if array_class.on_load_block
21
20
  end
22
21
  response_agent.outer_result = { data: array.to_transport }
23
22
  response_agent.agent_result = { success: 'ok' }
@@ -4,7 +4,7 @@ module Isomorfeus
4
4
  module Data
5
5
  module Handler
6
6
  class Object < LucidHandler::Base
7
- on_request do |pub_sub_client, current_user, response_agent|
7
+ on_request do |response_agent|
8
8
  # promise_send_path('Isomorfeus::Data::Handler::Object', action, object_hash)
9
9
  response_agent.request.each_key do |array_class_name|
10
10
  if Isomorfeus.valid_array_class_name?(array_class_name)
@@ -13,11 +13,10 @@ module Isomorfeus
13
13
  props_json = response_agent.request[array_class_name]
14
14
  begin
15
15
  props = Oj.load(props_json, mode: :strict)
16
- props.merge!({pub_sub_client: pub_sub_client, current_user: current_user})
17
16
  if current_user.authorized?(array_class, :load, *props)
18
17
  array = array_class.load(props)
19
18
  array.instance_exec do
20
- array_class.on_load_block.call(pub_sub_client, current_user) if array_class.on_load_block
19
+ array_class.on_load_block.call() if array_class.on_load_block
21
20
  end
22
21
  response_agent.outer_result = { data: array.to_transport }
23
22
  response_agent.agent_result = { success: 'ok' }
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Data
3
- VERSION = '1.0.0.zeta12'
3
+ VERSION = '1.0.0.zeta13'
4
4
  end
5
5
  end
@@ -6,8 +6,6 @@ module LucidData
6
6
  if RUBY_ENGINE != 'opal'
7
7
  def self.inherited(base)
8
8
  Isomorfeus.add_valid_data_class(base)
9
- base.prop :pub_sub_client, default: nil
10
- base.prop :current_user, default: Anonymous.new
11
9
  end
12
10
  end
13
11
  end
@@ -3,7 +3,6 @@ module LucidData
3
3
  module Mixin
4
4
  def self.included(base)
5
5
  base.include(Enumerable)
6
- base.extend(LucidPropDeclaration::Mixin)
7
6
  base.extend(Isomorfeus::Data::GenericClassApi)
8
7
  base.include(Isomorfeus::Data::GenericInstanceApi)
9
8
 
@@ -59,7 +58,7 @@ module LucidData
59
58
  @key = key.to_s
60
59
  @class_name = self.class.name
61
60
  @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
62
- @_store_path = [:data_state, @class_name, @key, :elements]
61
+ _update_paths
63
62
  @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
64
63
  @_changed_array = nil
65
64
  @_composition = composition
@@ -84,6 +83,10 @@ module LucidData
84
83
  Redux.fetch_by_path(*@_store_path)
85
84
  end
86
85
 
86
+ def _update_paths
87
+ @_store_path = [:data_state, @class_name, @key, :elements]
88
+ end
89
+
87
90
  def changed?
88
91
  @_changed || !!@_changed_array
89
92
  end
@@ -344,27 +347,14 @@ module LucidData
344
347
  end
345
348
  alias prepend unshift
346
349
  else # RUBY_ENGINE
347
- unless base == LucidData::Array::Base
348
- Isomorfeus.add_valid_data_class(base)
349
- base.prop :pub_sub_client, default: nil
350
- base.prop :current_user, default: Anonymous.new
351
- end
350
+ Isomorfeus.add_valid_data_class(base) unless base == LucidData::Array::Base
352
351
 
353
352
  base.instance_exec do
354
- def load(key:, pub_sub_client: nil, current_user: nil)
355
- data = instance_exec(key: key, pub_sub_client: pub_sub_client, current_user: current_user, &@_load_block)
356
- revision = data.delete(:revision)
357
- elements = data.delete(:elements)
358
- self.new(key: key, revision: revision, elements: elements)
359
- end
360
-
361
- def save(key:, revision: nil, elements: nil, pub_sub_client: nil, current_user: nil)
362
- _validate_elements(elements)
363
- data = instance_exec(key: key, revision: revision, elements: elements,
364
- pub_sub_client: pub_sub_client, current_user: current_user, &@_save_block)
365
- revision = data.delete(:revision)
366
- elements = data.delete(:elements)
367
- self.new(key: key, revision: revision, elements: elements)
353
+ def instance_from_transport(instance_data, _included_items_data)
354
+ key = instance_data[self.name].keys.first
355
+ revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
356
+ elements = instance_data[self.name][key].key?('elements') ? instance_data[self.name][key]['elements'] : nil
357
+ new(key: key, revision: revision, elements: elements)
368
358
  end
369
359
  end
370
360
 
@@ -381,6 +371,10 @@ module LucidData
381
371
  @_raw_array = elements
382
372
  end
383
373
 
374
+ def _unchange!
375
+ @_changed = false
376
+ end
377
+
384
378
  def changed?
385
379
  @_changed
386
380
  end
@@ -392,7 +386,9 @@ module LucidData
392
386
  def to_transport
393
387
  hash = { 'elements' => @_raw_array }
394
388
  hash.merge!('revision' => revision) if revision
395
- { @class_name => { @key => hash }}
389
+ result = { @class_name => { @key => hash }}
390
+ result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
391
+ result
396
392
  end
397
393
 
398
394
  # Array methods
@@ -6,8 +6,6 @@ module LucidData
6
6
  if RUBY_ENGINE != 'opal'
7
7
  def self.inherited(base)
8
8
  Isomorfeus.add_valid_data_class(base)
9
- base.prop :pub_sub_client, default: nil
10
- base.prop :current_user, default: Anonymous.new
11
9
  end
12
10
  end
13
11
  end
@@ -3,7 +3,6 @@ module LucidData
3
3
  module Mixin
4
4
  def self.included(base)
5
5
  base.include(Enumerable)
6
- base.extend(LucidPropDeclaration::Mixin)
7
6
  base.include(Isomorfeus::Data::AttributeSupport)
8
7
  base.extend(Isomorfeus::Data::GenericClassApi)
9
8
  base.include(Isomorfeus::Data::GenericInstanceApi)
@@ -96,7 +95,9 @@ module LucidData
96
95
  def to_transport
97
96
  hash = { 'attributes' => _get_selected_attributes, 'nodes' => nodes_as_sids }
98
97
  hash.merge!('revision' => revision) if revision
99
- { @class_name => { @key => hash }}
98
+ result = { @class_name => { @key => hash }}
99
+ result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
100
+ result
100
101
  end
101
102
 
102
103
  def included_items_to_transport
@@ -113,8 +114,7 @@ module LucidData
113
114
  @class_name = self.class.name
114
115
  @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
115
116
  @_graph = graph
116
- @_store_path = [:data_state, @class_name, @key, :attributes]
117
- @_nodes_path = [:data_state, @class_name, @key, :nodes]
117
+ _update_paths
118
118
  @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
119
119
  @_composition = composition
120
120
  @_changed = false
@@ -158,6 +158,11 @@ module LucidData
158
158
  @_changed_collection = nil
159
159
  end
160
160
 
161
+ def _update_paths
162
+ @_store_path = [:data_state, @class_name, @key, :attributes]
163
+ @_nodes_path = [:data_state, @class_name, @key, :nodes]
164
+ end
165
+
161
166
  def nodes
162
167
  nodes_as_sids.map do |node_sid|
163
168
  node = Isomorfeus.instance_from_sid(node_sid)
@@ -450,40 +455,28 @@ module LucidData
450
455
  end
451
456
  alias prepend unshift
452
457
  else # RUBY_ENGINE
453
- unless base == LucidData::Collection::Base
454
- Isomorfeus.add_valid_data_class(base)
455
- base.prop :pub_sub_client, default: nil
456
- base.prop :current_user, default: Anonymous.new
457
- end
458
+ Isomorfeus.add_valid_data_class(base) unless base == LucidData::Collection::Base
458
459
 
459
460
  base.instance_exec do
460
- def load(key:, pub_sub_client: nil, current_user: nil)
461
- data = instance_exec(key: key, pub_sub_client: pub_sub_client, current_user: current_user, &@_load_block)
462
- revision = data.delete(:revision)
463
- attributes = data.delete(:attributes)
464
- documents = data.delete(:documents)
465
- vertexes = data.delete(:vertexes)
466
- vertices = data.delete(:vertices)
467
- nodes = data.delete(:nodes)
468
- self.new(key: key, revision: revision, attributes: attributes, documents: documents, vertexes: vertexes, vertices: vertices,
469
- nodes: nodes)
470
- end
471
-
472
- def save(key:, revision: nil, attributes: nil, documents: nil, vertexes: nil, vertices: nil, nodes: nil,
473
- pub_sub_client: nil, current_user: nil)
474
- val_nodes = documents || nodes || vertexes || vertices
475
- _validate_attributes(attributes) if self.class.attribute_conditions.any?
476
- _validate_nodes(val_nodes) if self.class.node_conditions.any?
477
- data = instance_exec(key: key, revision: revision, attributes: attributes, documents: documents, vertexes: vertexes, vertices: vertices,
478
- nodes: nodes, pub_sub_client: pub_sub_client, current_user: current_user, &@_save_block)
479
- revision = data.delete(:revision)
480
- attributes = data.delete(:attributes)
481
- documents = data.delete(:documents)
482
- vertexes = data.delete(:vertexes)
483
- vertices = data.delete(:vertices)
484
- nodes = data.delete(:nodes)
485
- self.new(key: key, revision: revision, attributes: attributes, documents: documents, vertexes: vertexes, vertices: vertices,
486
- nodes: nodes)
461
+ def instance_from_transport(instance_data, included_items_data)
462
+ key = instance_data[self.name].keys.first
463
+ revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
464
+ attributes = instance_data[self.name][key].key?('attributes') ? instance_data[self.name][key]['attributes'] : nil
465
+ nodes_sids = instance_data[self.name][key].key?('nodes') ? instance_data[self.name][key]['nodes'] : []
466
+ nodes = []
467
+ nodes_sids.each do |sid|
468
+ node_class_name = sid[0]
469
+ node_key = sid[1]
470
+ Isomorfeus.raise_error "#{self.name}: #{node_class_name}: Not a valid LucidData class!" unless Isomorfeus.valid_data_class_name?(node_class_name)
471
+ if included_items_data.key?(node_class_name) && included_items_data[node_class_name].key?(node_key)
472
+ node_class = Isomorfeus.cached_data_class(node_class_name)
473
+ Isomorfeus.raise_error "#{self.name}: #{node_class_name}: Cannot get class!" unless node_class
474
+ node = node_class.instance_from_transport({ node_class_name => { node_key => included_items_data[node_class_name][node_key] }}, included_items_data)
475
+ Isomorfeus.raise_error "#{self.name}: #{node_class_name} with key #{node_key} could not be extracted from transport data!" unless node
476
+ nodes << node
477
+ end
478
+ end
479
+ new(key: key, revision: revision, attributes: attributes, nodes: nodes)
487
480
  end
488
481
  end
489
482
 
@@ -510,6 +503,10 @@ module LucidData
510
503
  @_sid_to_node_cache = {}
511
504
  end
512
505
 
506
+ def _unchange!
507
+ @_changed = false
508
+ end
509
+
513
510
  def nodes
514
511
  @_raw_collection
515
512
  end
@@ -6,8 +6,6 @@ module LucidData
6
6
  if RUBY_ENGINE != 'opal'
7
7
  def self.inherited(base)
8
8
  Isomorfeus.add_valid_data_class(base)
9
- base.prop :pub_sub_client, default: nil
10
- base.prop :current_user, default: Anonymous.new
11
9
  end
12
10
  end
13
11
  end
@@ -5,7 +5,6 @@ module LucidData
5
5
  # TODO include -> compose dsl
6
6
  # TODO inline store path
7
7
  def self.included(base)
8
- base.extend(LucidPropDeclaration::Mixin)
9
8
  base.include(Isomorfeus::Data::AttributeSupport)
10
9
  base.extend(Isomorfeus::Data::GenericClassApi)
11
10
  base.include(Isomorfeus::Data::GenericInstanceApi)
@@ -39,14 +38,14 @@ module LucidData
39
38
  end
40
39
 
41
40
  def _validate_part(access_name, part)
42
- raise "#{self.name}: No such part declared: '#{access_name}'!" unless parts.key?(access_name)
41
+ Isomorfeus.raise_error(message: "#{self.name}: No such part declared: '#{access_name}'!") unless parts.key?(access_name)
43
42
  Isomorfeus::Data::ElementValidator.new(self.name, part, parts[access_name]).validate!
44
43
  end
45
44
 
46
45
  def _validate_parts(many_parts)
47
46
  parts.each_key do |access_name|
48
47
  if parts[access_name].key?(:required) && parts[access_name][:required] && !many_parts.key?(attr)
49
- raise "Required part #{access_name} not given!"
48
+ Isomorfeus.raise_error(message: "Required part #{access_name} not given!")
50
49
  end
51
50
  end
52
51
  many_parts.each { |access_name, part| _validate_part(access_name, part) } if parts.any?
@@ -75,7 +74,9 @@ module LucidData
75
74
  parts.each do |name, instance|
76
75
  hash['parts'][name.to_s] = instance.to_sid if instance
77
76
  end
78
- { @class_name => { @key => hash }}
77
+ result = { @class_name => { @key => hash }}
78
+ result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
79
+ result
79
80
  end
80
81
 
81
82
  def included_items_to_transport
@@ -94,8 +95,7 @@ module LucidData
94
95
  @key = key.to_s
95
96
  @class_name = self.class.name
96
97
  @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
97
- @_store_path = [:data_state, @class_name, @key, :attributes]
98
- @_parts_path = [:data_state, @class_name, @key, :parts]
98
+ _update_paths
99
99
  @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
100
100
  @_changed = false
101
101
 
@@ -146,6 +146,11 @@ module LucidData
146
146
  nil
147
147
  end
148
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
+
149
154
  def _init_parts
150
155
  self.class.parts.each_key do |access_name|
151
156
  sid = Redux.fetch_by_path(*(@_parts_path + [access_name]))
@@ -165,31 +170,28 @@ module LucidData
165
170
  Redux.fetch_by_path(*@_composition_path)
166
171
  end
167
172
  else # RUBY_ENGINE
168
- unless base == LucidData::Composition::Base
169
- Isomorfeus.add_valid_data_class(base)
170
- base.prop :pub_sub_client, default: nil
171
- base.prop :current_user, default: Anonymous.new
172
- end
173
+ Isomorfeus.add_valid_data_class(base) unless base == LucidData::Composition::Base
173
174
 
174
175
  base.instance_exec do
175
- def load(key:, pub_sub_client: nil, current_user: nil)
176
- data = instance_exec(key: key, pub_sub_client: pub_sub_client, current_user: current_user, &@_load_block)
177
- revision = data.delete(:revision)
178
- attributes = data.delete(:attributes)
179
- parts = data.delete(:parts)
180
- self.new(key: key, revision: revision, parts: parts, attributes: attributes)
181
- end
182
-
183
- def save(key:, revision: nil, parts: nil, attributes: nil, pub_sub_client: nil, current_user: nil)
184
- attributes = {} unless attributes
185
- _validate_attributes(attributes)
186
- _validate_parts(parts)
187
- data = instance_exec(key: key, revision: revision, parts: parts, attributes: attributes,
188
- pub_sub_client: pub_sub_client, current_user: current_user, &@_save_block)
189
- revision = data.delete(:revision)
190
- attributes = data.delete(:attributes)
191
- parts = data.delete(:parts)
192
- self.new(key: key, revision: revision, parts: parts, attributes: attributes)
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'] : 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 "#{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 "#{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 "#{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)
193
195
  end
194
196
  end
195
197
 
@@ -214,6 +216,10 @@ module LucidData
214
216
  end
215
217
  end
216
218
 
219
+ def _unchange!
220
+ @_changed = false
221
+ end
222
+
217
223
  def parts
218
224
  @_parts
219
225
  end
@@ -6,8 +6,6 @@ module LucidData
6
6
  if RUBY_ENGINE != 'opal'
7
7
  def self.inherited(base)
8
8
  Isomorfeus.add_valid_data_class(base)
9
- base.prop :pub_sub_client, default: nil
10
- base.prop :current_user, default: Anonymous.new
11
9
  end
12
10
  end
13
11
  end
@@ -6,8 +6,6 @@ module LucidData
6
6
  if RUBY_ENGINE != 'opal'
7
7
  def self.inherited(base)
8
8
  Isomorfeus.add_valid_data_class(base)
9
- base.prop :pub_sub_client, default: nil
10
- base.prop :current_user, default: Anonymous.new
11
9
  end
12
10
  end
13
11
  end
@@ -2,7 +2,6 @@ module LucidData
2
2
  module Edge
3
3
  module Mixin
4
4
  def self.included(base)
5
- base.extend(LucidPropDeclaration::Mixin)
6
5
  base.include(Isomorfeus::Data::AttributeSupport)
7
6
  base.extend(Isomorfeus::Data::GenericClassApi)
8
7
  base.include(Isomorfeus::Data::GenericInstanceApi)
@@ -57,7 +56,9 @@ module LucidData
57
56
  "from" => from_as_sid,
58
57
  "to" => to_as_sid }
59
58
  hash.merge!("revision" => revision) if revision
60
- { @class_name => { @key => hash }}
59
+ result = { @class_name => { @key => hash }}
60
+ result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
61
+ result
61
62
  end
62
63
 
63
64
  if RUBY_ENGINE == 'opal'
@@ -65,9 +66,7 @@ module LucidData
65
66
  @key = key.to_s
66
67
  @class_name = self.class.name
67
68
  @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
68
- @_store_path = [:data_state, @class_name, @key, :attributes]
69
- @_from_path = [:data_state, @class_name, @key, :from]
70
- @_to_path = [:data_state, @class_name, @key, :to]
69
+ _update_paths
71
70
  @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
72
71
  @_collection = collection
73
72
  @_composition = composition
@@ -113,6 +112,12 @@ module LucidData
113
112
  @_changed = false
114
113
  end
115
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
+
116
121
  def each(&block)
117
122
  _get_attributes.each(&block)
118
123
  end
@@ -162,32 +167,31 @@ module LucidData
162
167
  node
163
168
  end
164
169
  else # RUBY_ENGINE
165
- unless base == LucidData::Edge::Base || base == LucidData::Link::Base
166
- Isomorfeus.add_valid_data_class(base)
167
- base.prop :pub_sub_client, default: nil
168
- base.prop :current_user, default: Anonymous.new
169
- end
170
+ Isomorfeus.add_valid_data_class(base) unless base == LucidData::Edge::Base || base == LucidData::Link::Base
170
171
 
171
172
  base.instance_exec do
172
- def load(key:, pub_sub_client: nil, current_user: nil)
173
- data = instance_exec(key: key, pub_sub_client: pub_sub_client, current_user: current_user, &@_load_block)
174
- revision = data.delete(:revision)
175
- from = data.delete(:from)
176
- to = data.delete(:to)
177
- attributes = data.delete(:attributes)
178
- self.new(key: key, revision: revision, from: from, to: to, attributes: attributes)
179
- end
180
-
181
- def save(key:, revision: nil, from:, to:, attributes: nil, pub_sub_client: nil, current_user: nil)
182
- attributes = {} unless attributes
183
- _validate_attributes(attributes)
184
- data = instance_exec(key: key, revision: revision, from: from, to: to, attributes: attributes,
185
- pub_sub_client: pub_sub_client, current_user: current_user, &@_save_block)
186
- revision = data.delete(:revision)
187
- from = data.delete(:from)
188
- to = data.delete(:to)
189
- attributes = data.delete(:attributes)
190
- self.new(key: key, revision: revision, from: from, to: to, attributes: attributes)
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'] : 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 "#{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 "#{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 "#{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])
191
195
  end
192
196
  end
193
197
 
@@ -218,6 +222,10 @@ module LucidData
218
222
  end
219
223
  end
220
224
 
225
+ def _unchange!
226
+ @_changed =false
227
+ end
228
+
221
229
  def each(&block)
222
230
  @_raw_attributes.each(&block)
223
231
  end
@@ -237,7 +245,7 @@ module LucidData
237
245
  end
238
246
 
239
247
  def from=(node)
240
- raise "A invalid 'from' was given" unless node
248
+ Isomorfeus.raise_error(message: "A invalid 'from' was given") unless node
241
249
  changed!
242
250
  old_from = from
243
251
  if node.respond_to?(:to_sid)
@@ -257,7 +265,7 @@ module LucidData
257
265
  end
258
266
 
259
267
  def to=(node)
260
- raise "A invalid 'to' was given" unless node
268
+ Isomorfeus.raise_error(message: "A invalid 'to' was given") unless node
261
269
  old_to = to
262
270
  changed!
263
271
  if node.respond_to?(:to_sid)