evt-schema 2.2.7.1 → 2.3.0.1

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: 68ebbe603540d26bdbfcbd9e1045b4ee75914532233e91cf8a60cc99031ec3c4
4
- data.tar.gz: 5cd65b8c2d22371c71b699aa91d9bf5293100a6eecfcbc2dcafbadd1c70c9ffd
3
+ metadata.gz: f332c2468a6e32cfd2cfdcdea372f004c620ca7679ad146ed8c63f66d851dbc0
4
+ data.tar.gz: 3bd8893da9e6c466bba9175747402531f56df1f9cf32644297231bd1de0c502e
5
5
  SHA512:
6
- metadata.gz: 4fe3f97a14704837d44bc716939ab242b892d486c17eba2d173564f725aeb1d903fdf5a5639440893875a27ed2e28cbc84b75b9100b0a3502410d9b6167912c7
7
- data.tar.gz: ef4bbbb81d4665f243dd7b60c945d1866b81142d0bf4193543960f8741f0ed2a6d4be7604e864cbc4ab79f494ca94c93dd893816f9a7e233ee6b6acdb4b839cd
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
- 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/fixtures CHANGED
@@ -1 +1 @@
1
- lib/schema/Users/sbellware/projects/eventide/schema-fixtures/lib/schema/fixtures
1
+ /Users/sbellware/projects/eventide/schema-fixtures/lib/schema/fixtures
@@ -1 +1 @@
1
- lib/schema/Users/sbellware/projects/eventide/schema-fixtures/lib/schema/fixtures.rb
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.attribute_names.include?(control_name)
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.attribute_names.include?(compare_name)
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
- 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.1
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: 2020-07-23 00:00:00.000000000 Z
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.1.2
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: []