evt-schema 2.2.7.2 → 2.3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ba3db2edbbe435d203deacf8e1adf8371126f4233496668a4a3bf64e0f9b7b9
4
- data.tar.gz: 327690e6aac9bf21458776935ab4213d62b45bf109290bcb416ac18fea0912de
3
+ metadata.gz: d3799452dd8ae40202fbebec160485b2fb4810e5ecb873b1a4520a98e48117a3
4
+ data.tar.gz: 989066b6a844b998e8b8debfe8d20cec98014ca3a227e2693c61ff578bf79462
5
5
  SHA512:
6
- metadata.gz: 7244b65f846380ea41de0f6b19ed6c1bac4b67ca7843e6e0ea20903627904c58879a3d703f4cd5f35caa23e4b5569cb8a7948523ea18bba02d5cf304ed6f6b06
7
- data.tar.gz: 8d7418966296aa94c6df0bc79abc30b8d2e06e8cdd46bcc8a65f20fbd92052b1d763a0596951011aaaaf10273931b9f4082cbb8972381aedbfe86a446b3192a9
6
+ metadata.gz: e0c2a231c2ceccd4d2a4b8472f43d23f78ef1fa18fc0ac673b1ad2eaf2d30b7afe7fffccc02f86753b517e4078fe32353765c19f78a832beac208caa763d8c3a
7
+ data.tar.gz: ffd08b7990b33add23ff1daada6031a30c1c96d2d70ee58ebc7fee895f305ca38b1a0c6f24c3b59f60776152e55a7fd4864bd7909aced652673036365da911db
@@ -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
- instance.transform_read(data)
28
- set_attributes(instance, data, strict)
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/schema.rb CHANGED
@@ -161,24 +161,35 @@ module Schema
161
161
  end
162
162
  end
163
163
 
164
- def attributes
165
- transient_attributes = []
166
- if self.class.respond_to?(:transient_attributes)
167
- transient_attributes = self.class.transient_attributes
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 = self.class.attributes.each_with_object({}) do |attribute, attributes|
171
- next if transient_attributes.include?(attribute.name)
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
- alias :to_h :attributes
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.2.7.2
4
+ version: 2.3.0.2
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: 2020-07-23 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-attribute
@@ -110,20 +110,19 @@ files:
110
110
  - lib/schema/controls/schema.rb
111
111
  - lib/schema/controls/schema/different.rb
112
112
  - lib/schema/data_structure.rb
113
- - lib/schema/fixtures
114
- - lib/schema/fixtures.rb
115
113
  - lib/schema/schema.rb
116
114
  - lib/schema/schema/attribute.rb
117
115
  - lib/schema/schema/compare.rb
118
116
  - lib/schema/schema/compare/comparison.rb
119
117
  - lib/schema/schema/compare/comparison/entry.rb
118
+ - lib/schema/scratch.rb
120
119
  - lib/schema/validation/error.rb
121
120
  - lib/schema/validation/nil_attributes.rb
122
121
  homepage: https://github.com/eventide-project/schema
123
122
  licenses:
124
123
  - MIT
125
124
  metadata: {}
126
- post_install_message:
125
+ post_install_message:
127
126
  rdoc_options: []
128
127
  require_paths:
129
128
  - lib
@@ -138,8 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
137
  - !ruby/object:Gem::Version
139
138
  version: '0'
140
139
  requirements: []
141
- rubygems_version: 3.1.2
142
- signing_key:
140
+ rubygems_version: 3.3.3
141
+ signing_key:
143
142
  specification_version: 4
144
143
  summary: Primitives for schema and data structure
145
144
  test_files: []
data/lib/schema/fixtures DELETED
@@ -1 +0,0 @@
1
- lib/schema/Users/sbellware/projects/eventide/schema-fixtures/lib/schema/fixtures
@@ -1 +0,0 @@
1
- lib/schema/Users/sbellware/projects/eventide/schema-fixtures/lib/schema/fixtures.rb