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
@@ -1,168 +0,0 @@
1
- module LucidHash
2
- module Mixin
3
- def self.included(base)
4
- if RUBY_ENGINE != 'opal'
5
- Isomorfeus.add_valid_hash_class(base) unless base == LucidHash::Base
6
- end
7
-
8
- base.extend(LucidPropDeclaration::Mixin)
9
-
10
- def to_gid
11
- [@class_name, @props_json]
12
- end
13
-
14
- def to_transport(inline: false)
15
- if inline
16
- { '_inline' => { @props_json => to_h }}
17
- else
18
- { 'hashes' => { @class_name => { @props_json => to_h }}}
19
- end
20
- end
21
-
22
- base.instance_exec do
23
- def on_load_block
24
- @on_load_block
25
- end
26
-
27
- def query_block
28
- @query_block
29
- end
30
- end
31
-
32
- if RUBY_ENGINE == 'opal'
33
- def initialize(store_path: nil, validated_props: nil)
34
- @props = validated_props
35
- @props_json = @props.to_json if @props
36
- @class_name = self.class.name
37
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
38
- @store_path = store_path ? store_path : [:data_state, :hashes, @class_name]
39
- end
40
-
41
- def loaded?
42
- Redux.fetch_by_path(*(@store_path + [@props_json])) ? true : false
43
- end
44
-
45
- def [](name)
46
- path = @store_path + [@props_json, name]
47
- result = Redux.fetch_by_path(*path)
48
- result ? result : nil
49
- end
50
-
51
- def key?(name)
52
- path = @store_path + [@props_json, name]
53
- Redux.fetch_by_path(*path) ? true : false
54
- end
55
-
56
- def method_missing(method_name, *args, &block)
57
- path = @store_path + [@props_json]
58
- raw_hash = Redux.fetch_by_path(*path)
59
- if raw_hash
60
- Hash.new(raw_hash).send(method_name, *args, &block)
61
- else
62
- Hash.new.send(method_name, *args, &block)
63
- end
64
- end
65
-
66
- def to_h
67
- raw_hash = Redux.fetch_by_path(*(@store_path + [@props_json]))
68
- raw_hash ? Hash.new(raw_hash) : {}
69
- end
70
-
71
- base.instance_exec do
72
- def load(props_hash = {})
73
- validate_props(props_hash)
74
- instance = self.new(validated_props: Isomorfeus::Data::Props.new(props_hash))
75
- self.promise_load(props_hash, instance) unless instance.loaded?
76
- instance
77
- end
78
-
79
- def on_load(&block)
80
- end
81
-
82
- def promise_load(props_hash = {}, instance = nil)
83
- unless instance
84
- validate_props(props_hash)
85
- instance = self.new(validated_props: Isomorfeus::Data::Props.new(props_hash))
86
- end
87
-
88
- props_json = instance.instance_variable_get(:@props_json)
89
-
90
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Data::Handler::HashLoadHandler', self.name, props_json).then do |agent|
91
- if agent.processed
92
- agent.result
93
- else
94
- agent.processed = true
95
- if agent.response.key?(:error)
96
- `console.error(#{agent.response[:error].to_n})`
97
- raise agent.response[:error]
98
- end
99
- Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
100
- agent.result = instance
101
- end
102
- end
103
- end
104
-
105
- def query
106
- nil
107
- end
108
- end
109
- else # RUBY_ENGINE
110
- unless base == LucidHash::Base
111
- base.prop :pub_sub_client, default: nil
112
- base.prop :current_user, default: nil
113
- end
114
-
115
- def initialize(store_path: nil, validated_props: nil)
116
- @props = validated_props
117
- @props_json = @props.to_json if @props
118
- @loaded = false
119
- @class_name = self.class.name
120
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
121
- end
122
-
123
- def loaded?
124
- @loaded
125
- end
126
-
127
- def [](name)
128
- @data_hash[name]
129
- end
130
-
131
- def method_missing(method_name, *args, &block)
132
- @data_hash.send(method_name, *args, &block)
133
- end
134
-
135
- def to_h
136
- @data_hash.to_h.transform_keys { |k| k.to_s }
137
- end
138
-
139
- base.instance_exec do
140
- def load(props_hash = {})
141
- validate_props(props_hash)
142
- instance = self.new(validated_props: Isomorfeus::Data::Props.new(props_hash))
143
- instance.instance_exec do
144
- @data_hash = self.class.query_block.call(props_hash)
145
- @loaded = true
146
- end
147
- instance
148
- end
149
-
150
- def on_load(&block)
151
- @on_load_block = block
152
- end
153
-
154
- def promise_load(props_hash = {}, instance = nil)
155
- instance = self.load(props_hash)
156
- result_promise = Promise.new
157
- result_promise.resolve(instance)
158
- result_promise
159
- end
160
-
161
- def query(&block)
162
- @query_block = block
163
- end
164
- end
165
- end # RUBY_ENGINE
166
- end
167
- end
168
- end
@@ -1,5 +0,0 @@
1
- module LucidNode
2
- class Base
3
- include LucidNode::Mixin
4
- end
5
- end
@@ -1,198 +0,0 @@
1
- # api
2
- # class:
3
- # attribute :my_attribute, server_only: false|true, class: ClassName, is_a: ClassName, default: value, validate: block
4
- # my_node.class.attributes
5
- # my_node.class.attribute_options
6
- # instance:
7
- # my_node.my_attribute
8
- # my_node.my_attribute = value
9
- # my_node.changed_attributes
10
- # my_node.changed?
11
- # my_node.loaded?
12
- # my_node.valid_attribute?(attr, value)
13
- # my_node.validate_attribute!(attr, value)
14
- # my_node.to_transport
15
-
16
- module LucidNode
17
- module Mixin
18
- def self.included(base)
19
- attr_reader :id
20
-
21
- def ==(other_node)
22
- eql?(other_node)
23
- end
24
-
25
- def eql?(other_node)
26
- @id == other_node.id && @class_name == other_node.instance_variable_get(:@class_name)
27
- end
28
-
29
- def id=(new_id)
30
- new_id = new_id.to_s
31
- changed_attributes[:id] = new_id
32
- @id = new_id
33
- end
34
-
35
- def changed_attributes
36
- @changed_attributes ||= Isomorfeus::Data::Props.new({})
37
- end
38
-
39
- def changed?
40
- changed_attributes.any?
41
- end
42
-
43
- def to_cid
44
- [@class_name, @id]
45
- end
46
-
47
- def valid_attribute?(attr, value)
48
- begin
49
- validate_attribute!(attr, value)
50
- true
51
- rescue
52
- false
53
- end
54
- end
55
-
56
- def validate_attribute!(attr, value)
57
- attr_options = self.class.attribute_options[attr]
58
-
59
- if attr_options.key?(:class)
60
- raise "#{attr}: value class is not #{attr_options[:class]}!" unless value.class == attr_options[:class]
61
- end
62
-
63
- if attr_options.key?(:is_a)
64
- raise "#{attr}: value is not a #{attr_options[:class]}!" unless value.is_a?(attr_options[:is_a])
65
- end
66
-
67
- if attr_options.key?(:validate)
68
- raise "#{attr}: value failed validation!" unless attr_options[:validate].call(value)
69
- end
70
- end
71
-
72
- base.instance_exec do
73
- def query_block
74
- @query_block
75
- end
76
-
77
- def attributes
78
- attribute_options.keys
79
- end
80
-
81
- def attribute_options
82
- @attribute_options ||= { id: {} }
83
- end
84
-
85
- def node_from_cid(cid)
86
- Isomorfeus.cached_node_class(cid[0]).new({id: cid[1]})
87
- end
88
- end
89
-
90
- if RUBY_ENGINE == 'opal'
91
- def initialize(attributes_hash = nil)
92
- attributes_hash = {} unless attributes_hash
93
- self.class.attributes.each do |attr|
94
- if attributes_hash.key?(attr)
95
- validate_attribute!(attr, attributes_hash[attr])
96
- changed_attributes[attr] = attributes_hash[attr]
97
- elsif self.class.attribute_options[attr].key?(:default)
98
- changed_attributes[attr] = self.class.attribute_options[attr][:default]
99
- end
100
- end
101
- @id = attributes_hash[:id].to_s
102
- @id = "new_#{object_id}" if @id.empty?
103
- @class_name = self.class.name
104
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
105
- end
106
-
107
- def loaded?
108
- Redux.fetch_by_path(:data_state, :node, @class_name, :instances, @id) ? true : false
109
- end
110
-
111
- def to_transport(*args)
112
- final_attributes = {}
113
- self.class.attributes.each do |attr|
114
- next if attr == :id
115
- final_attributes[attr] = send(attr)
116
- end
117
- { 'nodes' => { @class_name => { @id => { attributes: final_attributes }}}}
118
- end
119
-
120
- base.instance_exec do
121
- def attribute(name, options = {})
122
- attribute_options[name] = options
123
-
124
- define_method(name) do
125
- if changed_attributes.key?(name)
126
- changed_attributes[name]
127
- else
128
- Redux.fetch_by_path(:data_state, :nodes, @class_name, @id, :attributes, name)
129
- end
130
- end
131
-
132
- define_method("#{name}=") do |arg|
133
- validate_attribute!(name, arg)
134
- changed_attributes.set(name, arg)
135
- end
136
- end
137
-
138
- def query
139
- nil
140
- end
141
- end
142
- else # RUBY_ENGINE
143
- def initialize(attributes_hash = nil)
144
- attributes_hash = {} unless attributes_hash
145
- given_attributes = Isomorfeus::Data::Props.new(attributes_hash)
146
- valid_attributes_hash = {}
147
- self.class.attributes.each do |attr|
148
- if given_attributes.key?(attr)
149
- validate_attribute!(attr, given_attributes[attr])
150
- valid_attributes_hash[attr] = given_attributes[attr]
151
- elsif self.class.attribute_options[attr].key?(:default)
152
- valid_attributes_hash[attr] = self.class.attribute_options[attr][:default]
153
- end
154
- end
155
- @attributes = Isomorfeus::Data::Props.new(valid_attributes_hash)
156
- @id = @attributes[:id].to_s
157
- @id = "new_#{object_id}" if @id.empty?
158
- @class_name = self.class.name
159
- @class_name = @class_name.split('>::').last if @class_name.start_with?('#<')
160
- end
161
-
162
- def loaded?
163
- true
164
- end
165
-
166
- def to_transport(*args)
167
- final_attributes = {}
168
- self.class.attributes.each do |attr|
169
- next if attr == :id
170
- include_attribute = @attributes.key?(attr)
171
- include_attribute = !self.class.attribute_options[attr][:server_only] if self.class.attribute_options[attr].key?(:server_only)
172
- final_attributes[attr.to_s] = send(attr) if include_attribute
173
- end
174
- { 'nodes' => { @class_name => { @id => { 'attributes' => final_attributes }}}}
175
- end
176
-
177
- base.instance_exec do
178
- def attribute(name, options = {})
179
- attribute_options[name] = options
180
-
181
- define_method(name) do
182
- if changed_attributes.key?(name)
183
- changed_attributes[name]
184
- else
185
- @attributes[name]
186
- end
187
- end
188
-
189
- define_method("#{name}=") do |arg|
190
- validate_attribute!(name, arg)
191
- changed_attributes.set(name, arg)
192
- end
193
- end
194
- end
195
- end # RUBY_ENGINE
196
- end
197
- end
198
- end