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,413 @@
1
+ module LucidData
2
+ module Hash
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(Enumerable)
6
+ base.extend(LucidPropDeclaration::Mixin)
7
+ base.extend(Isomorfeus::Data::GenericClassApi)
8
+ base.include(Isomorfeus::Data::GenericInstanceApi)
9
+
10
+ attr_accessor :default
11
+ attr_accessor :default_proc
12
+
13
+ base.instance_exec do
14
+ def attribute_conditions
15
+ @attribute_conditions ||= {}
16
+ end
17
+
18
+ def valid_attribute?(attr_name, attr_value)
19
+ return true unless @attribute_conditions
20
+ Isomorfeus::Props::Validator.new(self.name, attr_name, attr_value, attribute_conditions[attr_name]).validate!
21
+ rescue
22
+ false
23
+ end
24
+ end
25
+
26
+ def composition
27
+ @_composition
28
+ end
29
+
30
+ def composition=(c)
31
+ @_composition = c
32
+ end
33
+
34
+ def changed!
35
+ @_composition.changed! if @_composition
36
+ @_changed = true
37
+ end
38
+
39
+ def to_transport
40
+ hash = { 'attributes' => to_h }
41
+ hash['revision'] = revision if revision
42
+ { @class_name => { @key => hash }}
43
+ end
44
+
45
+ def _validate_attribute(attr_name, attr_val)
46
+ Isomorfeus::Props::Validator.new(@class_name, attr_name, attr_val, self.class.attribute_conditions[attr_name]).validate!
47
+ end
48
+
49
+ if RUBY_ENGINE == 'opal'
50
+ base.instance_exec do
51
+ def attribute(name, options = {})
52
+ attribute_conditions[name] = options
53
+
54
+ define_method(name) do
55
+ result = _get_attribute(name)
56
+ if result
57
+ result
58
+ elsif !@_default_proc
59
+ @_default
60
+ else
61
+ @_default_proc.call(self, name)
62
+ end
63
+ end
64
+
65
+ define_method("#{name}=") do |val|
66
+ _validate_attribute(name, val) if @_validate_attributes
67
+ @_changed_attributes[name] = val
68
+ end
69
+ end
70
+ end
71
+
72
+ def initialize(key:, revision: nil, attributes: nil, default: nil, composition: nil, &block)
73
+ @_default = default
74
+ @_default_proc = block
75
+ @key = key.to_s
76
+ @class_name = self.class.name
77
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
78
+ @_store_path = [:data_state, @class_name, @key, :attributes]
79
+ @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
80
+ @_changed = false
81
+ @_changed_attributes = {}
82
+ @_composition = composition
83
+ @_validate_attributes = self.class.attribute_conditions.any?
84
+ attributes = {} unless attributes
85
+ if @_validate_attributes
86
+ attributes.each { |a,v| _validate_attribute(a, v) }
87
+ end
88
+ raw_attributes = Redux.fetch_by_path(*@_store_path)
89
+ if `raw_attributes === null`
90
+ @_changed_attributes = !attributes ? {} : attributes
91
+ elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
92
+ @_changed_attributes = attributes
93
+ end
94
+ end
95
+
96
+ def _get_attribute(name)
97
+ return @_changed_attributes[name] if @_changed_attributes.key?(name)
98
+ path = @_store_path + [name]
99
+ result = Redux.fetch_by_path(*path)
100
+ return nil if `result === null`
101
+ result
102
+ end
103
+
104
+ def _get_attributes
105
+ raw_attributes = Redux.fetch_by_path(*@_store_path)
106
+ hash = ::Hash.new(raw_attributes)
107
+ hash.merge!(@_changed_attributes) if @_changed_attributes
108
+ hash
109
+ end
110
+
111
+ def _load_from_store!
112
+ @_changed = false
113
+ @_changed_attributes = {}
114
+ end
115
+
116
+ def changed?
117
+ @_changed || @_changed_attributes.any?
118
+ end
119
+
120
+ def each(&block)
121
+ _get_attributes.each(&block)
122
+ end
123
+
124
+ def [](name)
125
+ result = _get_attribute(name)
126
+ return result if result
127
+ return @_default unless @_default_proc
128
+ @_default_proc.call(self, name)
129
+ end
130
+
131
+ def []=(name, val)
132
+ _validate_attribute(name, val) if @_validate_attributes
133
+ changed!
134
+ @_changed_attributes[name] = val
135
+ end
136
+
137
+ def compact!
138
+ result = _get_attributes.compact!
139
+ return nil if result.nil?
140
+ @_changed_attributes = result
141
+ changed!
142
+ self
143
+ end
144
+
145
+ def delete(name)
146
+ hash = _get_attributes
147
+ result = hash.delete(name)
148
+ @_changed_attributes = hash
149
+ changed!
150
+ result
151
+ end
152
+
153
+ def delete_if(&block)
154
+ hash = _get_attributes
155
+ result = hash.delete_if(&block)
156
+ @_changed_attributes = hash
157
+ changed!
158
+ result
159
+ end
160
+
161
+ def method_missing(method_name, *args, &block)
162
+ if method_name.end_with?('=')
163
+ val = args[0]
164
+ _validate_attribute(method_name, val) if @_validate_attributes
165
+ changed!
166
+ @_changed_attributes[method_name] = val
167
+ elsif args.size == 0 && hash.key?(method_name)
168
+ result = _get_attribute(method_name)
169
+ return result if result
170
+ return @_default unless @_default_proc
171
+ @_default_proc.call(self, method_name)
172
+ else
173
+ hash = _get_attributes
174
+ hash.send(name, *args, &block)
175
+ end
176
+ end
177
+
178
+ def key?(name)
179
+ _get_attribute(method_name) ? true : false
180
+ end
181
+ alias has_key? key?
182
+
183
+ def keep_if(&block)
184
+ raw_hash = _get_attributes
185
+ raw_hash.keep_if(&block)
186
+ @_changed_attributes = raw_hash
187
+ changed!
188
+ self
189
+ end
190
+
191
+ def merge!(*args)
192
+ @_changed_attributes = _get_attributes.merge!(*args)
193
+ changed!
194
+ self
195
+ end
196
+
197
+ def reject!(&block)
198
+ hash = _get_attributes
199
+ result = hash.reject!(&block)
200
+ return nil if result.nil?
201
+ @_changed_attributes = hash
202
+ changed!
203
+ self
204
+ end
205
+
206
+ def select!(&block)
207
+ hash = _get_attributes
208
+ result = hash.select!(&block)
209
+ return nil if result.nil?
210
+ @_changed_attributes = hash
211
+ changed!
212
+ self
213
+ end
214
+ alias filter! select!
215
+
216
+ def shift
217
+ hash = _get_attributes
218
+ result = hash.shift
219
+ @_changed_attributes = hash
220
+ changed!
221
+ result
222
+ end
223
+
224
+ def store(name, val)
225
+ _validate_attribute(name, val) if @_validate_attributes
226
+ @_changed_attributes[name] = val
227
+ changed!
228
+ val
229
+ end
230
+
231
+ def to_h
232
+ _get_attributes.dup
233
+ end
234
+
235
+ def transform_keys!(&block)
236
+ @_changed_attributes = _get_attributes.transform_keys!(&block)
237
+ changed!
238
+ self
239
+ end
240
+
241
+ def transform_values!(&block)
242
+ @_changed_attributes = _get_attributes.transform_values!(&block)
243
+ changed!
244
+ self
245
+ end
246
+
247
+ def update(*args)
248
+ @_changed_attributes = _get_attributes.update(*args)
249
+ changed!
250
+ self
251
+ end
252
+ else # RUBY_ENGINE
253
+ unless base == LucidData::Hash::Base
254
+ Isomorfeus.add_valid_data_class(base)
255
+ base.prop :pub_sub_client, default: nil
256
+ base.prop :current_user, default: Anonymous.new
257
+ end
258
+
259
+ base.instance_exec do
260
+ def attribute(name, options = {})
261
+ attribute_conditions[name] = options
262
+
263
+ define_method(name) do
264
+ @_raw_attributes[name]
265
+ end
266
+
267
+ define_method("#{name}=") do |val|
268
+ _validate_attribute(name, val) if @_validate_attributes
269
+ changed!
270
+ @_raw_attributes[name] = val
271
+ end
272
+ end
273
+
274
+ def load(key:, pub_sub_client: nil, current_user: nil)
275
+ data = instance_exec(key: key, &@_load_block)
276
+ revision = nil
277
+ revision = data.delete(:revision) if data.key?(:revision)
278
+ attributes = data.delete(:attributes)
279
+ self.new(key: key, revision: revision, attributes: attributes)
280
+ end
281
+ end
282
+
283
+ def initialize(key:, revision: nil, attributes: nil, composition: nil)
284
+ @key = key.to_s
285
+ @class_name = self.class.name
286
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
287
+ @_revision = revision
288
+ @_composition = composition
289
+ @_changed = false
290
+ @_validate_attributes = self.class.attribute_conditions.any?
291
+ attributes = {} unless attributes
292
+ if @_validate_attributes
293
+ attributes.each { |a,v| _validate_attribute(a, v) }
294
+ end
295
+ @_raw_attributes = attributes
296
+ end
297
+
298
+ def changed?
299
+ @_changed
300
+ end
301
+
302
+ def each(&block)
303
+ @_raw_attributes.each(&block)
304
+ end
305
+
306
+ def [](name)
307
+ @_raw_attributes[name]
308
+ end
309
+
310
+ def []=(name, val)
311
+ _validate_attribute(name, val) if @_validate_attributes
312
+ changed!
313
+ @_raw_attributes[name] = val
314
+ end
315
+
316
+ def compact!(&block)
317
+ result = @_raw_attributes.compact!(&block)
318
+ return nil if result.nil?
319
+ changed!
320
+ self
321
+ end
322
+
323
+ def delete(element, &block)
324
+ result = @_raw_attributes.delete(element, &block)
325
+ changed!
326
+ result
327
+ end
328
+
329
+ def delete_if(&block)
330
+ @_raw_attributes.delete_if(&block)
331
+ changed!
332
+ self
333
+ end
334
+
335
+ def keep_if(&block)
336
+ @_raw_attributes.keep_if(&block)
337
+ changed!
338
+ self
339
+ end
340
+
341
+ def method_missing(method_name, *args, &block)
342
+ if method_name.end_with?('=')
343
+ val = args[0]
344
+ _validate_attribute(name, val) if @_validate_attributes
345
+ changed!
346
+ @_raw_attributes[name] = val
347
+ elsif args.size == 0 && @_raw_attributes.key?(method_name)
348
+ @_raw_attributes[method_name]
349
+ else
350
+ @_raw_attributes.send(method_name, *args, &block)
351
+ end
352
+ end
353
+
354
+ def merge!(*args)
355
+ @_raw_attributes.merge!(*args)
356
+ changed!
357
+ self
358
+ end
359
+
360
+ def reject!(&block)
361
+ result = @_raw_attributes.reject!(&block)
362
+ return nil if result.nil?
363
+ changed!
364
+ self
365
+ end
366
+
367
+ def select!(&block)
368
+ result = @_raw_attributes.select!(&block)
369
+ return nil if result.nil?
370
+ changed!
371
+ self
372
+ end
373
+ alias filter! select!
374
+
375
+ def shift
376
+ result = @_raw_attributes.shift
377
+ changed!
378
+ result
379
+ end
380
+
381
+ def store(name, val)
382
+ _validate_attribute(name, val) if @_validate_attributes
383
+ changed!
384
+ @_raw_attributes[name] = val
385
+ end
386
+
387
+ # If using def the method to_h gets not overwritten.
388
+ base.define_method :to_h do
389
+ @_raw_attributes.dup.transform_keys!(&:to_s)
390
+ end
391
+
392
+ def transform_keys!(&block)
393
+ @_raw_attributes.transform_keys!(&block)
394
+ changed!
395
+ self
396
+ end
397
+
398
+ def transform_values!(&block)
399
+ @_raw_attributes.transform_values!(&block)
400
+ changed!
401
+ self
402
+ end
403
+
404
+ def update(*args)
405
+ @_raw_attributes.update(*args)
406
+ changed!
407
+ self
408
+ end
409
+ end # RUBY_ENGINE
410
+ end
411
+ end
412
+ end
413
+ end
@@ -0,0 +1,15 @@
1
+ module LucidData
2
+ module Link
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,9 @@
1
+ module LucidData
2
+ module Link
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(LucidData::Edge::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module LucidData
2
+ module LinkCollection
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,9 @@
1
+ module LucidData
2
+ module LinkCollection
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(LucidData::EdgeCollection::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module LucidData
2
+ module Node
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,192 @@
1
+ module LucidData
2
+ module Node
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 edges
41
+ graph&.edges_for_node(self)
42
+ end
43
+
44
+ def linked_nodes
45
+ graph&.linked_nodes_for_node(self)
46
+ end
47
+
48
+ def method_missing(method_name, *args, &block)
49
+ if graph
50
+ method_name_s = method_name.to_s
51
+ singular_name = method_name_s.singularize
52
+ plural_name = method_name_s.pluralize
53
+ node_edges = edges
54
+ if method_name_s == plural_name
55
+ # return all nodes
56
+ nodes = []
57
+ sid = to_sid
58
+ node_edges.each do |edge|
59
+ from_sid = edge.from_as_sid
60
+ to_sid = edge.to_as_sid
61
+ node = if from_sid[0].underscore == singular_name && to_sid == sid
62
+ edge.from
63
+ elsif to_sid[0].underscore == singular_name && from_sid == sid
64
+ edge.to
65
+ end
66
+ nodes << node if node
67
+ end
68
+ return nodes
69
+ elsif method_name_s == singular_name
70
+ # return one node
71
+ sid = to_sid
72
+ node_edges.each do |edge|
73
+ from_sid = edge.from_as_sid
74
+ to_sid = edge.to_as_sid
75
+ node = if from_sid[0].underscore == singular_name && to_sid == sid
76
+ edge.from
77
+ elsif to_sid[0].underscore == singular_name && from_sid == sid
78
+ edge.to
79
+ end
80
+ return node if node
81
+ end
82
+ nil
83
+ end
84
+ else
85
+ super(method_name, *args, &block)
86
+ end
87
+ end
88
+
89
+ def to_transport
90
+ hash = _get_selected_attributes
91
+ hash.merge!("revision" => revision) if revision
92
+ { @class_name => { @key => hash }}
93
+ end
94
+
95
+ if RUBY_ENGINE == 'opal'
96
+ def initialize(key:, revision: nil, attributes: nil, graph: nil, composition: nil)
97
+ @key = key.to_s
98
+ @class_name = self.class.name
99
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
100
+ @_store_path = [:data_state, @class_name, @key]
101
+ @_revision = revision ? revision : Redux.fetch_by_path(:data_state, :revision, @class_name, @key)
102
+ @_graph = graph
103
+ @_composition = composition
104
+ @_changed = false
105
+ loaded = loaded?
106
+ if attributes
107
+ attributes.each { |a,v| _validate_attribute(a, v) }
108
+ if loaded
109
+ raw_attributes = Redux.fetch_by_path(*@_store_path)
110
+ if `raw_attributes === null`
111
+ @_changed_attributes = !attributes ? {} : attributes
112
+ elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
113
+ @_changed_attributes = attributes
114
+ end
115
+ else
116
+ @_changed_attributes = attributes
117
+ end
118
+ else
119
+ @_changed_attributes = {}
120
+ end
121
+ end
122
+
123
+ def _load_from_store!
124
+ @_changed_attributes = {}
125
+ @_changed = false
126
+ end
127
+
128
+ def each(&block)
129
+ _get_attributes.each(&block)
130
+ end
131
+
132
+ def [](name)
133
+ _get_attribute(name)
134
+ end
135
+
136
+ def []=(name, val)
137
+ _validate_attribute(name, val)
138
+ changed!
139
+ @_changed_attributes[name] = val
140
+ end
141
+ else # RUBY_ENGINE
142
+ unless base == LucidData::Node::Base || base == LucidData::Document::Base || base == LucidData::Vertex::Base
143
+ Isomorfeus.add_valid_data_class(base)
144
+ base.prop :pub_sub_client, default: nil
145
+ base.prop :current_user, default: Anonymous.new
146
+ end
147
+
148
+ base.instance_exec do
149
+ def load(key:, pub_sub_client: nil, current_user: nil)
150
+ data = instance_exec(key: key, &@_load_block)
151
+ revision = nil
152
+ revision = data.delete(:revision) if data.key?(:revision)
153
+ data.delete(:_key)
154
+ attributes = data.key?(:attributes) ? data.delete(:attributes) : data
155
+ self.new(key: key, revision: revision, attributes: attributes)
156
+ end
157
+ end
158
+
159
+ def initialize(key:, revision: nil, attributes: nil, collection: nil, composition: nil)
160
+ @key = key.to_s
161
+ @class_name = self.class.name
162
+ @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
163
+ @_revision = revision
164
+ @_composition = composition
165
+ @_collection = collection
166
+ @_changed = false
167
+ @_validate_attributes = self.class.attribute_conditions.any?
168
+ attributes = {} unless attributes
169
+ if @_validate_attributes
170
+ attributes.each { |a,v| _validate_attribute(a, v) }
171
+ end
172
+ @_raw_attributes = attributes
173
+ end
174
+
175
+ def each(&block)
176
+ @_raw_attributes.each(&block)
177
+ end
178
+
179
+ def [](name)
180
+ @_raw_attributes[name]
181
+ end
182
+
183
+ def []=(name, val)
184
+ _validate_attribute(name, val)
185
+ changed!
186
+ @_raw_attributes[name] = val
187
+ end
188
+ end # RUBY_ENGINE
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,13 @@
1
+ module LucidStorableObject
2
+ class Base
3
+ include LucidStorableObject::Mixin
4
+
5
+ if RUBY_ENGINE != 'opal'
6
+ def self.inherited(base)
7
+ Isomorfeus.add_valid_data_class(base)
8
+ base.prop :pub_sub_client, default: nil
9
+ base.prop :current_user, default: Anonymous.new
10
+ end
11
+ end
12
+ end
13
+ end