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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5288c5f08a6cb9216328257e14606f41c6c9f9a7f970036dbd2e8d57502b2fb6
4
- data.tar.gz: 473c71fd6c84860abca1ad373391cb44828ee8beaed4ce1af71d65a3e79e3f88
3
+ metadata.gz: 1394418f9a7765f02a9214dbeb633e6a873e6bba5f63d2e51612de04cc581adf
4
+ data.tar.gz: ab90990899ce3b0cc1140c8e5cf45d2777a57a74ab8b2161f06a3836749fa7f8
5
5
  SHA512:
6
- metadata.gz: 57a9193f4b2ac22cd924c600ee4cfa3fc2f4ee25e4a6b59492b1e6f47c10d620b426b4e04e260d9341f6058df88387348bc16a3b23ba580e5bad138dfe337953
7
- data.tar.gz: dc600448b3907f8675f049fde21d1098241c394eeed0e3134972e7b22ea0353a7a5b57aaf00e0038d8eb7ce4def20bf37a47b10c7898d110fc46696eb2dc4687
6
+ metadata.gz: 642842b79e5630a72a583ff48f96264b68b11bf4c670e02fe9a1243ec801cf751a3ea1ce410912810438021decf3f88c17426deea0e460df6b6c4f100dd1492e
7
+ data.tar.gz: 78fc44830ceb7366fa7c77e8fffa6da6cd9a4a12e4936a0738f1c9041ef8738ac095e4b089837a2a8685ffcc67672407b5ef86363f5e6ab5f88670deffa60925
data/LICENSE CHANGED
@@ -1,21 +1,47 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 Jan Biedermann
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Jan Biedermann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ uri module in opal directory originally taken from
24
+ https://github.com/ajjahn/opal-uri:
25
+
26
+ Copyright (c) 2015 Jamie Gaskins
27
+
28
+ MIT License
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining
31
+ a copy of this software and associated documentation files (the
32
+ "Software"), to deal in the Software without restriction, including
33
+ without limitation the rights to use, copy, modify, merge, publish,
34
+ distribute, sublicense, and/or sell copies of the Software, and to
35
+ permit persons to whom the Software is furnished to do so, subject to
36
+ the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be
39
+ included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
42
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
44
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
45
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
46
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
47
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,46 +1,38 @@
1
- # isomorfeus-data
2
-
3
- Data access for Isomorfeus.
4
-
5
- *Use Ruby for Graphs! ... and more!*
6
-
7
- ### Community and Support
8
- At the [Isomorfeus Framework Project](http://isomorfeus.com)
9
-
10
- ### Overview
11
-
12
- Isomorfeus Data provides convenient access to all sorts of data for the distributes, isomorphic system.
13
- Data is available in the same way on clients and server.
14
-
15
- Isomorfeus Data supports arrays, hashes, collections, graphs, nodes, edges and compositions of any of those which can be loaded with one requests.
16
-
17
- All LucidData classes are database agnostic. Any ORM or data source supported by ruby can be used.
18
- Data must then be shaped (usually in to a Hash or Array) to fit the Isomorfeus Data classes.
19
-
20
-
21
- ### Core Concepts and Common API
22
-
23
- - [Core Concepts](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/concepts.md)
24
- - [Common API](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/common_api.md)
25
- - [Data Policy](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_policy.md)
26
-
27
- ### Available Classes
28
-
29
- All classes follow the common principles and the common API above.
30
-
31
- - [LucidData::Array](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_array.md) - A array, easily accessible on client and server
32
- - [LucidData::Collections](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_collection.md) - A collection of LucidData::Node or LucidData::Vertex or LucidData::Document objects
33
- - [LucidData::Composition](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_composition.md) - A composition of any of those other classes, even graphs, for easy, one request access to arbitrary data
34
- - [LucidData::Document, LucidData::Node, LucidData::Vertex](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_node.md) - A node/document/vertex, can be used stand alone, in a collection or in a graph
35
- - [LucidData::Edge, LucidData::Link](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_edge.md) - A edge/link, can be used standalone, in a collection or in a graph
36
- - [LucidData::EdgeCollection, LucidData::LinkCollection](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_edge_collection.md) - A collection of LucidData::Edge or LucidData::Link objects
37
- - [LucidData::Graph](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_graph.md) - A graph, which can be build from several LucidData::Collection objects and LucidData::EdgeCollection objects
38
- - [LucidData::Hash](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_hash.md) - A hash, easily accessible on client and server
39
-
40
- For convenience the following generic classes are provided. They can be used when creating a separate class wouldn't be useful:
41
- - LucidData::GenericCollection
42
- - LucidData::GenericEdgeCollection
43
- - LucidData::GenericNode
44
- - LucidData::GenericEdge
45
-
46
- (more to come soon)
1
+ # isomorfeus-data
2
+
3
+ Data access for Isomorfeus.
4
+
5
+ *Use Ruby for Graphs! ... and more!*
6
+
7
+ ### Community and Support
8
+ At the [Isomorfeus Framework Project](http://isomorfeus.com)
9
+
10
+ ### Overview
11
+
12
+ Isomorfeus Data provides convenient access to data for the distributed, isomorphic system.
13
+ Data is available in the same way on clients and server.
14
+
15
+ Isomorfeus Data supports documents, objects and files.
16
+
17
+ ### Core Concepts and Common API
18
+
19
+ - [Core Concepts](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/concepts.md)
20
+ - [Common API](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/common_api.md)
21
+ - [Data Policy](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_policy.md)
22
+
23
+ ### Available Classes
24
+
25
+ All classes follow the common principles and the common API above.
26
+
27
+ - [LucidDocument](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_document.md) - for textual data with fields
28
+ - [LucidObject](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_object.md) - for objects with attributes
29
+ - [LucidFile](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_file.md) - for files like images, pdfs, etc.
30
+ - [LucidQuery](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_query.md) - for isomorphic queries.
31
+
32
+ ### Storage
33
+
34
+ isomorfeus-data relies on:
35
+ - [isomorfeus-ferret](https://github.com/isomorfeus/isomorfeus-ferret) as storage and index for documents
36
+ - [isomorfeus-hamster](https://github.com/isomorfeus/isomorfeus-hamster) as storage and index for objects
37
+ - the Filesystem for files
38
+ - [Oj](https://github.com/ohler55/oj) for serialization
@@ -1,176 +1,176 @@
1
- module Isomorfeus
2
- module Data
3
- module AttributeSupport
4
- def self.included(base)
5
- base.instance_exec do
6
- def attribute_conditions
7
- @attribute_conditions ||= {}
8
- end
9
-
10
- def valid_attribute?(attr_name, attr_value)
11
- Isomorfeus::Props::Validator.new(self.name, attr_name, attr_value, attribute_conditions[attr_name]).validate!
12
- rescue
13
- false
14
- end
15
-
16
- def validate
17
- Isomorfeus::Props::ValidateHashProxy.new
18
- end
19
-
20
- def _validate_attribute(attr_name, attr_val)
21
- Isomorfeus.raise_error(message: "#{self.name}: No such attribute declared: '#{attr_name}'!") unless attribute_conditions.key?(attr_name)
22
- Isomorfeus::Props::Validator.new(self.name, attr_name, attr_val, attribute_conditions[attr_name]).validate!
23
- end
24
-
25
- def _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| _validate_attribute(attr, val) }
32
- end
33
- end
34
-
35
- def _validate_attribute(attr_name, value)
36
- self.class._validate_attribute(attr_name, value)
37
- end
38
-
39
- def _validate_attributes(attrs)
40
- self.class._validate_attributes(attrs)
41
- end
42
-
43
- def exclude_attributes(*attrs)
44
- @_excluded_attributes = attrs
45
- end
46
-
47
- def select_attributes(*attrs)
48
- @_selected_attributes = attrs
49
- end
50
-
51
- if RUBY_ENGINE == 'opal'
52
- base.instance_exec do
53
- def attribute(name, options = {})
54
- attribute_conditions[name] = options
55
-
56
- define_method(name) do
57
- _get_attribute(name)
58
- end
59
-
60
- define_method("#{name}=") do |val|
61
- _validate_attribute(name, val)
62
- changed!
63
- @_changed_attributes[name] = val
64
- end
65
- end
66
- end
67
-
68
- def validate_attributes_function
69
- %x{
70
- if (typeof self.validate_attributes_function === 'undefined') {
71
- self.validate_attributes_function = function(attributes_object) {
72
- try { self.$_validate_attributes(Opal.Hash.$new(attributes_object)) }
73
- catch (e) { return e.message; }
74
- }
75
- }
76
- return self.validate_attributes_function;
77
- }
78
- end
79
-
80
- def validate_attribute_function(attr)
81
- function_name = "validate_attribute_#{attr}_function"
82
- %x{
83
- if (typeof self[function_name] === 'undefined') {
84
- self[function_name] = function(value) {
85
- try { self.$_validate_attribute(attribute, value); }
86
- catch (e) { return e.message; }
87
- }
88
- }
89
- return self[function_name];
90
- }
91
- end
92
-
93
- def _get_attribute(name)
94
- return @_changed_attributes[name] if @_changed_attributes.key?(name)
95
- path = @_store_path + [name]
96
- result = Redux.fetch_by_path(*path)
97
- %x{
98
- if (result === null) { return nil; }
99
- else if (result instanceof Object && !(result instanceof Array)) {
100
- return Opal.Hash.$new(result);
101
- } else { return result; }
102
- }
103
- end
104
-
105
- def attributes
106
- raw_attributes = Redux.fetch_by_path(*@_store_path)
107
- hash = Hash.new(raw_attributes)
108
- hash.merge!(@_changed_attributes) if @_changed_attributes
109
- hash
110
- end
111
-
112
- def native_attributes
113
- Redux.fetch_by_path(*@_store_path)
114
- end
115
-
116
- def _get_selected_attributes
117
- sel_attributes = attributes.dup
118
- if @_selected_attributes && !@_selected_attributes.empty?
119
- sel_attributes.each_key do |attr|
120
- unless @_selected_attributes.include?(attr) || @_selected_attributes.include?(attr)
121
- sel_attributes.delete(attr)
122
- end
123
- end
124
- end
125
- if @_excluded_attributes && !@_excluded_attributes.empty?
126
- @_excluded_attributes.each { |attr| sel_attributes.delete(attr) }
127
- end
128
- sel_attributes
129
- end
130
- else
131
- base.instance_exec do
132
- def attribute(name, options = {})
133
- attribute_conditions[name] = options
134
-
135
- define_method(name) do
136
- @_raw_attributes[name]
137
- end
138
-
139
- define_method("#{name}=") do |val|
140
- _validate_attribute(name, val)
141
- changed!
142
- @_raw_attributes[name] = val
143
- end
144
- end
145
- end
146
-
147
- def attributes
148
- @_raw_attributes
149
- end
150
-
151
- def native_attributes
152
- @_raw_attributes
153
- end
154
-
155
- def _get_selected_attributes
156
- sel_attributes = attributes.transform_keys(&:to_s)
157
- self.class.attribute_conditions.each do |attr, options|
158
- sel_attributes.delete(attr.to_s) if options[:server_only]
159
- end
160
- if @_selected_attributes && !@_selected_attributes.empty?
161
- sel_attributes.each_key do |attr|
162
- unless @_selected_attributes.include?(attr.to_sym) || @_selected_attributes.include?(attr)
163
- sel_attributes.delete(attr)
164
- end
165
- end
166
- end
167
- if @_excluded_attributes && !@_excluded_attributes.empty?
168
- @_excluded_attributes.each { |attr| sel_attributes.delete(attr.to_s) }
169
- end
170
- sel_attributes
171
- end
172
- end
173
- end
174
- end
175
- end
176
- end
1
+ module Isomorfeus
2
+ module Data
3
+ module AttributeSupport
4
+ def self.included(base)
5
+ base.instance_exec do
6
+ def attribute_conditions
7
+ @attribute_conditions ||= {}
8
+ end
9
+
10
+ def indexed_attributes
11
+ @indexed_attributes ||= {}
12
+ end
13
+
14
+ def valid_attribute?(attr_name, attr_value)
15
+ Isomorfeus::Props::Validator.new(self.name, attr_name, attr_value, attribute_conditions[attr_name]).validate!
16
+ rescue
17
+ false
18
+ end
19
+
20
+ def validate
21
+ Isomorfeus::Props::ValidateHashProxy.new
22
+ end
23
+
24
+ def _validate_attribute(attr_name, attr_val)
25
+ Isomorfeus.raise_error(message: "#{self.name}: No such attribute declared: '#{attr_name}'!") unless attribute_conditions.key?(attr_name)
26
+ Isomorfeus::Props::Validator.new(self.name, attr_name, attr_val, attribute_conditions[attr_name]).validate!
27
+ end
28
+
29
+ def _validate_attributes(attrs)
30
+ attribute_conditions.each_key do |attr|
31
+ if attribute_conditions[attr].key?(:required) && attribute_conditions[attr][:required] && !attrs.key?(attr)
32
+ Isomorfeus.raise_error(message: "Required attribute #{attr} not given!")
33
+ end
34
+ end
35
+ attrs.each { |attr, val| _validate_attribute(attr, val) }
36
+ end
37
+ end
38
+
39
+ def _validate_attribute(attr_name, value)
40
+ self.class._validate_attribute(attr_name, value)
41
+ end
42
+
43
+ def _validate_attributes(attrs)
44
+ self.class._validate_attributes(attrs)
45
+ end
46
+
47
+ def exclude_attributes(*attrs)
48
+ @_excluded_attributes = attrs
49
+ end
50
+
51
+ def select_attributes(*attrs)
52
+ @_selected_attributes = attrs
53
+ end
54
+
55
+ if RUBY_ENGINE == 'opal'
56
+ base.instance_exec do
57
+ def attribute(name, options = {})
58
+ indexed = options.delete(:index)
59
+ indexed_attributes[name] = indexed if indexed
60
+ attribute_conditions[name] = options
61
+
62
+ define_method(name) do
63
+ _get_attribute(name)
64
+ end
65
+
66
+ define_method("#{name}=") do |val|
67
+ _validate_attribute(name, val)
68
+ changed!
69
+ @_changed_attributes[name] = val
70
+ end
71
+ end
72
+ end
73
+
74
+ def validate_attributes_function
75
+ %x{
76
+ if (typeof self.validate_attributes_function === 'undefined') {
77
+ self.validate_attributes_function = function(attributes_object) {
78
+ try { self.$_validate_attributes(Opal.Hash.$new(attributes_object)) }
79
+ catch (e) { return e.message; }
80
+ }
81
+ }
82
+ return self.validate_attributes_function;
83
+ }
84
+ end
85
+
86
+ def validate_attribute_function(attr)
87
+ function_name = "validate_attribute_#{attr}_function"
88
+ %x{
89
+ if (typeof self[function_name] === 'undefined') {
90
+ self[function_name] = function(value) {
91
+ try { self.$_validate_attribute(attribute, value); }
92
+ catch (e) { return e.message; }
93
+ }
94
+ }
95
+ return self[function_name];
96
+ }
97
+ end
98
+
99
+ def _get_attribute(name)
100
+ return @_changed_attributes[name] if @_changed_attributes.key?(name)
101
+ path = @_store_path + [name]
102
+ result = Redux.fetch_by_path(*path)
103
+ %x{
104
+ if (result === null) { return nil; }
105
+ else if (result instanceof Object && !(result instanceof Array)) {
106
+ return Opal.Hash.$new(result);
107
+ } else { return result; }
108
+ }
109
+ end
110
+
111
+ def attributes
112
+ raw_attributes = Redux.fetch_by_path(*@_store_path)
113
+ hash = Hash.new(raw_attributes)
114
+ hash.merge!(@_changed_attributes) if @_changed_attributes
115
+ hash
116
+ end
117
+
118
+ def _get_selected_attributes
119
+ sel_attributes = attributes.dup
120
+ if @_selected_attributes && !@_selected_attributes.empty?
121
+ sel_attributes.each_key do |attr|
122
+ unless @_selected_attributes.include?(attr) || @_selected_attributes.include?(attr)
123
+ sel_attributes.delete(attr)
124
+ end
125
+ end
126
+ end
127
+ if @_excluded_attributes && !@_excluded_attributes.empty?
128
+ @_excluded_attributes.each { |attr| sel_attributes.delete(attr) }
129
+ end
130
+ sel_attributes
131
+ end
132
+ else
133
+ base.instance_exec do
134
+ def attribute(name, options = {})
135
+ indexed = options.delete(:index)
136
+ indexed_attributes[name] = indexed if indexed
137
+ attribute_conditions[name] = options
138
+
139
+ define_method(name) do
140
+ @_raw_attributes[name]
141
+ end
142
+
143
+ define_method("#{name}=") do |val|
144
+ _validate_attribute(name, val)
145
+ changed!
146
+ @_raw_attributes[name] = val
147
+ end
148
+ end
149
+ end
150
+
151
+ def attributes
152
+ @_raw_attributes
153
+ end
154
+
155
+ def _get_selected_attributes
156
+ sel_attributes = attributes.transform_keys(&:to_s)
157
+ self.class.attribute_conditions.each do |attr, options|
158
+ sel_attributes.delete(attr.to_s) if options[:server_only]
159
+ end
160
+ if @_selected_attributes && !@_selected_attributes.empty?
161
+ sel_attributes.each_key do |attr|
162
+ unless @_selected_attributes.include?(attr.to_sym) || @_selected_attributes.include?(attr)
163
+ sel_attributes.delete(attr)
164
+ end
165
+ end
166
+ end
167
+ if @_excluded_attributes && !@_excluded_attributes.empty?
168
+ @_excluded_attributes.each { |attr| sel_attributes.delete(attr.to_s) }
169
+ end
170
+ sel_attributes
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end