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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +47 -21
  3. data/README.md +38 -46
  4. data/lib/isomorfeus/data/attribute_support.rb +176 -176
  5. data/lib/isomorfeus/data/config.rb +79 -110
  6. data/lib/isomorfeus/data/element_validator.rb +147 -147
  7. data/lib/isomorfeus/data/ferret_accelerator.rb +66 -0
  8. data/lib/isomorfeus/data/field_support.rb +110 -0
  9. data/lib/isomorfeus/data/generic_class_api.rb +136 -116
  10. data/lib/isomorfeus/data/generic_instance_api.rb +150 -145
  11. data/lib/isomorfeus/data/hamster_accelerator.rb +87 -0
  12. data/lib/isomorfeus/data/hamster_storage_expander.rb +94 -0
  13. data/lib/isomorfeus/data/handler/generic.rb +134 -138
  14. data/lib/isomorfeus/data/reducer.rb +30 -30
  15. data/lib/isomorfeus/data/version.rb +4 -4
  16. data/lib/isomorfeus-data.rb +56 -64
  17. data/lib/isomorfeus_data/lucid_document/base.rb +10 -0
  18. data/lib/isomorfeus_data/lucid_document/mixin.rb +148 -0
  19. data/lib/isomorfeus_data/lucid_file/base.rb +10 -0
  20. data/lib/isomorfeus_data/lucid_file/mixin.rb +217 -0
  21. data/lib/isomorfeus_data/lucid_object/base.rb +10 -0
  22. data/lib/isomorfeus_data/lucid_object/mixin.rb +216 -0
  23. data/lib/isomorfeus_data/lucid_query/base.rb +10 -0
  24. data/lib/isomorfeus_data/lucid_query/mixin.rb +81 -0
  25. data/lib/isomorfeus_data/lucid_query_result.rb +97 -0
  26. data/opal/uri/common.rb +18 -0
  27. data/opal/uri/generic.rb +47 -0
  28. data/opal/uri.rb +29 -0
  29. metadata +85 -96
  30. data/lib/isomorfeus/data/handler/arango.rb +0 -56
  31. data/lib/isomorfeus/data/handler/object_call.rb +0 -40
  32. data/lib/isomorfeus/data/handler/object_store.rb +0 -40
  33. data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -13
  34. data/lib/isomorfeus_data/lucid_data/array/mixin.rb +0 -580
  35. data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -13
  36. data/lib/isomorfeus_data/lucid_data/collection/finders.rb +0 -83
  37. data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +0 -737
  38. data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -13
  39. data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +0 -234
  40. data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -13
  41. data/lib/isomorfeus_data/lucid_data/document/mixin.rb +0 -9
  42. data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -13
  43. data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +0 -286
  44. data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -13
  45. data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +0 -134
  46. data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +0 -747
  47. data/lib/isomorfeus_data/lucid_data/generic_collection.rb +0 -4
  48. data/lib/isomorfeus_data/lucid_data/generic_edge.rb +0 -4
  49. data/lib/isomorfeus_data/lucid_data/generic_edge_collection.rb +0 -4
  50. data/lib/isomorfeus_data/lucid_data/generic_node.rb +0 -4
  51. data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -13
  52. data/lib/isomorfeus_data/lucid_data/graph/finders.rb +0 -141
  53. data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +0 -489
  54. data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -13
  55. data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +0 -427
  56. data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -13
  57. data/lib/isomorfeus_data/lucid_data/link/mixin.rb +0 -9
  58. data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -13
  59. data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +0 -9
  60. data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -13
  61. data/lib/isomorfeus_data/lucid_data/node/mixin.rb +0 -232
  62. data/lib/isomorfeus_data/lucid_data/query/base.rb +0 -13
  63. data/lib/isomorfeus_data/lucid_data/query/mixin.rb +0 -83
  64. data/lib/isomorfeus_data/lucid_data/query_result.rb +0 -95
  65. data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -13
  66. data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +0 -9
  67. data/lib/lucid_arango/collection/base.rb +0 -13
  68. data/lib/lucid_arango/collection/mixin.rb +0 -18
  69. data/lib/lucid_arango/document/base.rb +0 -13
  70. data/lib/lucid_arango/document/mixin.rb +0 -9
  71. data/lib/lucid_arango/edge/base.rb +0 -13
  72. data/lib/lucid_arango/edge/mixin.rb +0 -18
  73. data/lib/lucid_arango/edge_collection/base.rb +0 -13
  74. data/lib/lucid_arango/edge_collection/mixin.rb +0 -18
  75. data/lib/lucid_arango/graph/base.rb +0 -13
  76. data/lib/lucid_arango/graph/mixin.rb +0 -18
  77. data/lib/lucid_arango/node/base.rb +0 -13
  78. data/lib/lucid_arango/node/mixin.rb +0 -79
  79. data/lib/lucid_arango/object/base.rb +0 -11
  80. data/lib/lucid_arango/object/mixin.rb +0 -158
  81. data/lib/lucid_arango/remote_object/base.rb +0 -11
  82. data/lib/lucid_arango/remote_object/mixin.rb +0 -17
  83. data/lib/lucid_arango/vertex/base.rb +0 -13
  84. data/lib/lucid_arango/vertex/mixin.rb +0 -9
@@ -1,427 +0,0 @@
1
- module LucidData
2
- module Hash
3
- module Mixin
4
- def self.included(base)
5
- base.include(Enumerable)
6
- base.include(Isomorfeus::Data::AttributeSupport)
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 valid_attribute?(attr_name, attr_value)
15
- return true unless attribute_conditions.any?
16
- Isomorfeus::Props::Validator.new(self.name, attr_name, attr_value, attribute_conditions[attr_name]).validate!
17
- rescue
18
- false
19
- end
20
-
21
- def _relaxed_validate_attribute(attr_name, attr_val)
22
- Isomorfeus::Props::Validator.new(@class_name, attr_name, attr_val, attribute_conditions[attr_name]).validate!
23
- end
24
-
25
- def _relaxed_validate_attributes(attrs)
26
- attribute_conditions.each_key do |attr|
27
- if attribute_conditions[attr].key?(:required) && attribute_conditions[attr][:required] && !attrs.key?(attr)
28
- Isomorfeus.raise_error(message: "Required attribute #{attr} not given!")
29
- end
30
- end
31
- attrs.each { |attr, val| _relaxed_validate_attribute(attr, val) } if attribute_conditions.any?
32
- end
33
- end
34
-
35
- def composition
36
- @_composition
37
- end
38
-
39
- def composition=(c)
40
- @_composition = c
41
- end
42
-
43
- def changed!
44
- @_composition.changed! if @_composition
45
- @_changed = true
46
- end
47
-
48
- def to_transport
49
- hash = { 'attributes' => to_h }
50
- hash['revision'] = revision if revision
51
- result = { @class_name => { @key => hash }}
52
- result.deep_merge!(@class_name => { @previous_key => { new_key: @key}}) if @previous_key
53
- result
54
- end
55
-
56
- def _relaxed_validate_attribute(attr_name, attr_val)
57
- self.class._relaxed_validate_attribute(attr_name, attr_val)
58
- end
59
-
60
- def _relaxed_validate_attributes(attrs)
61
- self.class._relaxed_validate_attributes(attrs)
62
- end
63
-
64
- if RUBY_ENGINE == 'opal'
65
- base.instance_exec do
66
- def attribute(name, options = {})
67
- attribute_conditions[name] = options
68
-
69
- define_method(name) do
70
- result = _get_attribute(name)
71
- if result
72
- result
73
- elsif !@_default_proc
74
- @_default
75
- else
76
- @_default_proc.call(self, name)
77
- end
78
- end
79
-
80
- define_method("#{name}=") do |val|
81
- _relaxed_validate_attribute(name, val) if @_validate_attributes
82
- @_changed_attributes[name] = val
83
- end
84
- end
85
- end
86
-
87
- def initialize(key:, revision: nil, attributes: nil, default: nil, composition: nil, &block)
88
- @_default = default
89
- @_default_proc = block
90
- @key = key.to_s
91
- @class_name = self.class.name
92
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
93
- _update_paths
94
- @_revision = revision ? revision : Redux.fetch_by_path(:data_state, @class_name, @key, :revision)
95
- @_changed = false
96
- @_changed_attributes = {}
97
- @_composition = composition
98
- @_validate_attributes = self.class.attribute_conditions.any?
99
- attributes = {} unless attributes
100
- _relaxed_validate_attributes(attributes) if @_validate_attributes
101
- raw_attributes = Redux.fetch_by_path(*@_store_path)
102
- if `raw_attributes === null`
103
- @_changed_attributes = !attributes ? {} : attributes
104
- elsif raw_attributes && !attributes.nil? && ::Hash.new(raw_attributes) != attributes
105
- @_changed_attributes = attributes
106
- end
107
- end
108
-
109
- def _get_attribute(name)
110
- return @_changed_attributes[name] if @_changed_attributes.key?(name)
111
- path = @_store_path + [name]
112
- result = Redux.fetch_by_path(*path)
113
- return nil if `result === null`
114
- result
115
- end
116
-
117
- def attributes
118
- raw_attributes = Redux.fetch_by_path(*@_store_path)
119
- hash = ::Hash.new(raw_attributes)
120
- hash.merge!(@_changed_attributes) if @_changed_attributes
121
- hash
122
- end
123
-
124
- def _load_from_store!
125
- @_changed = false
126
- @_changed_attributes = {}
127
- end
128
-
129
- def _update_paths
130
- @_store_path = [:data_state, @class_name, @key, :attributes]
131
- end
132
-
133
- def changed?
134
- @_changed || @_changed_attributes.any?
135
- end
136
-
137
- def each(&block)
138
- attributes.each(&block)
139
- end
140
-
141
- def [](name)
142
- result = _get_attribute(name)
143
- return result if result
144
- return @_default unless @_default_proc
145
- @_default_proc.call(self, name)
146
- end
147
-
148
- def []=(name, val)
149
- _relaxed_validate_attribute(name, val) if @_validate_attributes
150
- changed!
151
- @_changed_attributes[name] = val
152
- end
153
-
154
- def compact!
155
- result = attributes.compact!
156
- return nil if result.nil?
157
- @_changed_attributes = result
158
- changed!
159
- self
160
- end
161
-
162
- def delete(name)
163
- hash = attributes
164
- result = hash.delete(name)
165
- @_changed_attributes = hash
166
- changed!
167
- result
168
- end
169
-
170
- def delete_if(&block)
171
- hash = attributes
172
- result = hash.delete_if(&block)
173
- @_changed_attributes = hash
174
- changed!
175
- result
176
- end
177
-
178
- def method_missing(method_name, *args, &block)
179
- if method_name.end_with?('=')
180
- val = args[0]
181
- _relaxed_validate_attribute(method_name, val) if @_validate_attributes
182
- changed!
183
- @_changed_attributes[method_name] = val
184
- elsif args.size == 0 && hash.key?(method_name)
185
- result = _get_attribute(method_name)
186
- return result if result
187
- return @_default unless @_default_proc
188
- @_default_proc.call(self, method_name)
189
- else
190
- hash = attributes
191
- hash.send(name, *args, &block)
192
- end
193
- end
194
-
195
- def key?(name)
196
- _get_attribute(name) ? true : false
197
- end
198
- alias has_key? key?
199
-
200
- def keep_if(&block)
201
- raw_hash = attributes
202
- raw_hash.keep_if(&block)
203
- @_changed_attributes = raw_hash
204
- changed!
205
- self
206
- end
207
-
208
- def merge!(*args)
209
- @_changed_attributes = attributes.merge!(*args)
210
- changed!
211
- self
212
- end
213
-
214
- def reject!(&block)
215
- hash = attributes
216
- result = hash.reject!(&block)
217
- return nil if result.nil?
218
- @_changed_attributes = hash
219
- changed!
220
- self
221
- end
222
-
223
- def select!(&block)
224
- hash = attributes
225
- result = hash.select!(&block)
226
- return nil if result.nil?
227
- @_changed_attributes = hash
228
- changed!
229
- self
230
- end
231
- alias filter! select!
232
-
233
- def shift
234
- hash = attributes
235
- result = hash.shift
236
- @_changed_attributes = hash
237
- changed!
238
- result
239
- end
240
-
241
- def store(name, val)
242
- _relaxed_validate_attribute(name, val) if @_validate_attributes
243
- @_changed_attributes[name] = val
244
- changed!
245
- val
246
- end
247
-
248
- def to_h
249
- attributes.dup
250
- end
251
-
252
- def transform_keys!(&block)
253
- @_changed_attributes = attributes.transform_keys!(&block)
254
- changed!
255
- self
256
- end
257
-
258
- def transform_values!(&block)
259
- @_changed_attributes = attributes.transform_values!(&block)
260
- changed!
261
- self
262
- end
263
-
264
- def update(*args)
265
- @_changed_attributes = attributes.update(*args)
266
- changed!
267
- self
268
- end
269
- else # RUBY_ENGINE
270
- Isomorfeus.add_valid_data_class(base) unless base == LucidData::Hash::Base
271
-
272
- base.instance_exec do
273
- def attribute(name, options = {})
274
- attribute_conditions[name] = options
275
-
276
- define_method(name) do
277
- @_raw_attributes[name]
278
- end
279
-
280
- define_method("#{name}=") do |val|
281
- _relaxed_validate_attribute(name, val) if @_validate_attributes
282
- changed!
283
- @_raw_attributes[name] = val
284
- end
285
- end
286
-
287
- def instance_from_transport(instance_data, _included_items_data)
288
- key = instance_data[self.name].keys.first
289
- revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
290
- attributes = instance_data[self.name][key].key?('attributes') ? instance_data[self.name][key]['attributes'].transform_keys!(&:to_sym) : nil
291
- new(key: key, revision: revision, attributes: attributes)
292
- end
293
- end
294
-
295
- def initialize(key:, revision: nil, attributes: nil, composition: nil)
296
- @key = key.to_s
297
- @class_name = self.class.name
298
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
299
- @_revision = revision
300
- @_composition = composition
301
- @_changed = false
302
- @_validate_attributes = self.class.attribute_conditions.any?
303
- attributes = {} unless attributes
304
- _relaxed_validate_attributes(attributes) if @_validate_attributes
305
- @_raw_attributes = attributes
306
- end
307
-
308
- def _unchange!
309
- @_changed = false
310
- end
311
-
312
- def changed?
313
- @_changed
314
- end
315
-
316
- def each(&block)
317
- @_raw_attributes.each(&block)
318
- end
319
-
320
- def [](name)
321
- @_raw_attributes[name]
322
- end
323
-
324
- def []=(name, val)
325
- _relaxed_validate_attribute(name, val) if @_validate_attributes
326
- changed!
327
- @_raw_attributes[name] = val
328
- end
329
-
330
- def compact!(&block)
331
- result = @_raw_attributes.compact!(&block)
332
- return nil if result.nil?
333
- changed!
334
- self
335
- end
336
-
337
- def delete(element, &block)
338
- result = @_raw_attributes.delete(element, &block)
339
- changed!
340
- result
341
- end
342
-
343
- def delete_if(&block)
344
- @_raw_attributes.delete_if(&block)
345
- changed!
346
- self
347
- end
348
-
349
- def keep_if(&block)
350
- @_raw_attributes.keep_if(&block)
351
- changed!
352
- self
353
- end
354
-
355
- def method_missing(method_name, *args, &block)
356
- if method_name.end_with?('=')
357
- val = args[0]
358
- _relaxed_validate_attribute(name, val) if @_validate_attributes
359
- changed!
360
- @_raw_attributes[name] = val
361
- elsif args.size == 0 && @_raw_attributes.key?(method_name)
362
- @_raw_attributes[method_name]
363
- else
364
- @_raw_attributes.send(method_name, *args, &block)
365
- end
366
- end
367
-
368
- def merge!(*args)
369
- @_raw_attributes.merge!(*args)
370
- changed!
371
- self
372
- end
373
-
374
- def reject!(&block)
375
- result = @_raw_attributes.reject!(&block)
376
- return nil if result.nil?
377
- changed!
378
- self
379
- end
380
-
381
- def select!(&block)
382
- result = @_raw_attributes.select!(&block)
383
- return nil if result.nil?
384
- changed!
385
- self
386
- end
387
- alias filter! select!
388
-
389
- def shift
390
- result = @_raw_attributes.shift
391
- changed!
392
- result
393
- end
394
-
395
- def store(name, val)
396
- _relaxed_validate_attribute(name, val) if @_validate_attributes
397
- changed!
398
- @_raw_attributes[name] = val
399
- end
400
-
401
- # If using def the method to_h gets not overwritten.
402
- base.define_method :to_h do
403
- @_raw_attributes.dup.transform_keys!(&:to_s)
404
- end
405
-
406
- def transform_keys!(&block)
407
- @_raw_attributes.transform_keys!(&block)
408
- changed!
409
- self
410
- end
411
-
412
- def transform_values!(&block)
413
- @_raw_attributes.transform_values!(&block)
414
- changed!
415
- self
416
- end
417
-
418
- def update(*args)
419
- @_raw_attributes.update(*args)
420
- changed!
421
- self
422
- end
423
- end # RUBY_ENGINE
424
- end
425
- end
426
- end
427
- end
@@ -1,13 +0,0 @@
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
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
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
@@ -1,13 +0,0 @@
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
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
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
@@ -1,13 +0,0 @@
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
- end
10
- end
11
- end
12
- end
13
- end