evt-schema 2.2.7.1 → 2.3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema/controls/data_structure.rb +10 -0
- data/lib/schema/data_structure.rb +5 -2
- data/lib/schema/fixtures +1 -1
- data/lib/schema/fixtures.rb +1 -1
- data/lib/schema/schema/compare/comparison.rb +2 -2
- data/lib/schema/schema.rb +20 -9
- data/lib/schema/scratch.rb +50 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f332c2468a6e32cfd2cfdcdea372f004c620ca7679ad146ed8c63f66d851dbc0
|
4
|
+
data.tar.gz: 3bd8893da9e6c466bba9175747402531f56df1f9cf32644297231bd1de0c502e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a631fe2dbf4dba122f20a1fe81d8afe5b95e93297f4e0009e3e9afb907544f1f276b40e96adc5e364d387a527c1a0258251ee33abeb41c4d10463439405351
|
7
|
+
data.tar.gz: 29626ec60e70ac92def2e729a7097e2207ebdd96ca5c717129b78e64ab2db6e2c8fb64600b3a802ca46d074108d8ea30cbf818226e9972aaccf1635eae9513db
|
@@ -102,6 +102,16 @@ module Schema
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
105
|
+
|
106
|
+
module TransformReadFail
|
107
|
+
Error = Class.new(RuntimeError)
|
108
|
+
|
109
|
+
class Example < DataStructure::Example
|
110
|
+
def transform_read(data)
|
111
|
+
raise Error
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
105
115
|
end
|
106
116
|
end
|
107
117
|
end
|
@@ -24,8 +24,11 @@ module Schema
|
|
24
24
|
strict ||= false
|
25
25
|
|
26
26
|
new.tap do |instance|
|
27
|
-
|
28
|
-
|
27
|
+
if not data.empty?
|
28
|
+
instance.transform_read(data)
|
29
|
+
set_attributes(instance, data, strict)
|
30
|
+
end
|
31
|
+
|
29
32
|
instance.configure_dependencies
|
30
33
|
end
|
31
34
|
end
|
data/lib/schema/fixtures
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
/Users/sbellware/projects/eventide/schema-fixtures/lib/schema/fixtures
|
data/lib/schema/fixtures.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
/Users/sbellware/projects/eventide/schema-fixtures/lib/schema/fixtures.rb
|
@@ -50,12 +50,12 @@ module Schema
|
|
50
50
|
|
51
51
|
def self.build_entry(control_name, control, compare_name, compare)
|
52
52
|
control_class = control.class
|
53
|
-
if not control_class.
|
53
|
+
if not control_class.all_attribute_names.include?(control_name)
|
54
54
|
raise Error, "Attribute is not defined (Attribute Name: #{control_name.inspect}, Schema Class: #{control_class})"
|
55
55
|
end
|
56
56
|
|
57
57
|
compare_class = compare.class
|
58
|
-
if not compare_class.
|
58
|
+
if not compare_class.all_attribute_names.include?(compare_name)
|
59
59
|
raise Error, "Attribute is not defined (Attribute Name: #{compare_name.inspect}, Schema Class: #{compare_class})"
|
60
60
|
end
|
61
61
|
|
data/lib/schema/schema.rb
CHANGED
@@ -161,24 +161,35 @@ module Schema
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
def attributes
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
164
|
+
def attributes(include_transient: nil)
|
165
|
+
include_transient ||= false
|
166
|
+
|
167
|
+
attribute_names = self.class.attribute_names(include_transient: include_transient)
|
169
168
|
|
170
|
-
data =
|
171
|
-
|
172
|
-
attributes[attribute.name] = public_send(attribute.name)
|
169
|
+
data = attribute_names.each_with_object({}) do |attribute_name, attributes|
|
170
|
+
attributes[attribute_name] = public_send(attribute_name)
|
173
171
|
end
|
174
172
|
|
175
173
|
transform_write(data)
|
176
174
|
|
177
175
|
data
|
178
176
|
end
|
179
|
-
|
177
|
+
|
178
|
+
def to_h
|
179
|
+
attributes
|
180
|
+
end
|
181
|
+
|
182
|
+
def all_attributes
|
183
|
+
attributes(include_transient: true)
|
184
|
+
end
|
180
185
|
|
181
186
|
def ==(other, attributes_names=nil, ignore_class: nil)
|
187
|
+
ignore_class ||= false
|
188
|
+
|
189
|
+
if not ignore_class
|
190
|
+
return false if self.class != other.class
|
191
|
+
end
|
192
|
+
|
182
193
|
comparison = Compare.(self, other, attributes_names)
|
183
194
|
|
184
195
|
different = comparison.different?(ignore_class: ignore_class)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Foo.build
|
2
|
+
|
3
|
+
-> transform_read({})
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
class Thing
|
14
|
+
attribute :some_attribute, String
|
15
|
+
attribute :some_object, SomeClass
|
16
|
+
|
17
|
+
def self.transform_read(data)
|
18
|
+
some_object_data = data[:some_object] # => nil or some hash
|
19
|
+
|
20
|
+
if not some_object_data.nil?
|
21
|
+
foo_data = some_object_data[:foo] # => Error
|
22
|
+
end
|
23
|
+
|
24
|
+
some_object = SomeClass.build(some_object_data)
|
25
|
+
|
26
|
+
data[:some_object] = some_object
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class SomeClass
|
31
|
+
attribute :foo
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
data = {}
|
36
|
+
thing = Thing.build(data)
|
37
|
+
|
38
|
+
build(data) -> transform_read(data) # Rem: data is empty
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
thing = data[:some_atttribute]
|
47
|
+
# => nil
|
48
|
+
|
49
|
+
thing.other_thing
|
50
|
+
# => nil reference error
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-attribute
|
@@ -117,13 +117,14 @@ files:
|
|
117
117
|
- lib/schema/schema/compare.rb
|
118
118
|
- lib/schema/schema/compare/comparison.rb
|
119
119
|
- lib/schema/schema/compare/comparison/entry.rb
|
120
|
+
- lib/schema/scratch.rb
|
120
121
|
- lib/schema/validation/error.rb
|
121
122
|
- lib/schema/validation/nil_attributes.rb
|
122
123
|
homepage: https://github.com/eventide-project/schema
|
123
124
|
licenses:
|
124
125
|
- MIT
|
125
126
|
metadata: {}
|
126
|
-
post_install_message:
|
127
|
+
post_install_message:
|
127
128
|
rdoc_options: []
|
128
129
|
require_paths:
|
129
130
|
- lib
|
@@ -138,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
142
|
-
signing_key:
|
142
|
+
rubygems_version: 3.3.3
|
143
|
+
signing_key:
|
143
144
|
specification_version: 4
|
144
145
|
summary: Primitives for schema and data structure
|
145
146
|
test_files: []
|