isomorfeus-data 1.0.0.zeta22 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +47 -21
- data/README.md +38 -46
- data/lib/isomorfeus/data/attribute_support.rb +176 -176
- data/lib/isomorfeus/data/config.rb +79 -110
- data/lib/isomorfeus/data/element_validator.rb +147 -147
- data/lib/isomorfeus/data/ferret_accelerator.rb +66 -0
- data/lib/isomorfeus/data/field_support.rb +110 -0
- data/lib/isomorfeus/data/generic_class_api.rb +136 -118
- data/lib/isomorfeus/data/generic_instance_api.rb +150 -147
- data/lib/isomorfeus/data/hamster_accelerator.rb +87 -0
- data/lib/isomorfeus/data/hamster_storage_expander.rb +94 -0
- data/lib/isomorfeus/data/handler/generic.rb +134 -138
- data/lib/isomorfeus/data/reducer.rb +30 -30
- data/lib/isomorfeus/data/version.rb +4 -4
- data/lib/isomorfeus-data.rb +56 -64
- data/lib/isomorfeus_data/lucid_document/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_document/mixin.rb +148 -0
- data/lib/isomorfeus_data/lucid_file/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_file/mixin.rb +217 -0
- data/lib/isomorfeus_data/lucid_object/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_object/mixin.rb +216 -0
- data/lib/isomorfeus_data/lucid_query/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_query/mixin.rb +81 -0
- data/lib/isomorfeus_data/lucid_query_result.rb +97 -0
- data/opal/uri/common.rb +18 -0
- data/opal/uri/generic.rb +47 -0
- data/opal/uri.rb +29 -0
- metadata +85 -96
- data/lib/isomorfeus/data/handler/arango.rb +0 -56
- data/lib/isomorfeus/data/handler/object_call.rb +0 -40
- data/lib/isomorfeus/data/handler/object_store.rb +0 -40
- data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/array/mixin.rb +0 -580
- data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/collection/finders.rb +0 -83
- data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +0 -737
- data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +0 -234
- data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/document/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +0 -286
- data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +0 -134
- data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +0 -747
- data/lib/isomorfeus_data/lucid_data/generic_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_node.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/graph/finders.rb +0 -141
- data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +0 -489
- data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +0 -427
- data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/node/mixin.rb +0 -232
- data/lib/isomorfeus_data/lucid_data/query/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/query/mixin.rb +0 -84
- data/lib/isomorfeus_data/lucid_data/query_result.rb +0 -95
- data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +0 -9
- data/lib/lucid_arango/collection/base.rb +0 -13
- data/lib/lucid_arango/collection/mixin.rb +0 -18
- data/lib/lucid_arango/document/base.rb +0 -13
- data/lib/lucid_arango/document/mixin.rb +0 -9
- data/lib/lucid_arango/edge/base.rb +0 -13
- data/lib/lucid_arango/edge/mixin.rb +0 -18
- data/lib/lucid_arango/edge_collection/base.rb +0 -13
- data/lib/lucid_arango/edge_collection/mixin.rb +0 -18
- data/lib/lucid_arango/graph/base.rb +0 -13
- data/lib/lucid_arango/graph/mixin.rb +0 -18
- data/lib/lucid_arango/node/base.rb +0 -13
- data/lib/lucid_arango/node/mixin.rb +0 -79
- data/lib/lucid_arango/object/base.rb +0 -11
- data/lib/lucid_arango/object/mixin.rb +0 -159
- data/lib/lucid_arango/remote_object/base.rb +0 -11
- data/lib/lucid_arango/remote_object/mixin.rb +0 -17
- data/lib/lucid_arango/vertex/base.rb +0 -13
- data/lib/lucid_arango/vertex/mixin.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1394418f9a7765f02a9214dbeb633e6a873e6bba5f63d2e51612de04cc581adf
|
4
|
+
data.tar.gz: ab90990899ce3b0cc1140c8e5cf45d2777a57a74ab8b2161f06a3836749fa7f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
13
|
-
Data is available in the same way on clients and server.
|
14
|
-
|
15
|
-
Isomorfeus Data supports
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
- [
|
36
|
-
- [
|
37
|
-
-
|
38
|
-
- [
|
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
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def
|
21
|
-
Isomorfeus.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def
|
40
|
-
self.class.
|
41
|
-
end
|
42
|
-
|
43
|
-
def
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
def
|
48
|
-
@
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
define_method(
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
def
|
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
|