dry-schema 1.13.0 → 1.13.3
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 +4 -4
- data/CHANGELOG.md +20 -0
- data/LICENSE +1 -1
- data/README.md +3 -3
- data/dry-schema.gemspec +2 -2
- data/lib/dry/schema/config.rb +3 -1
- data/lib/dry/schema/dsl.rb +13 -5
- data/lib/dry/schema/extensions/struct.rb +25 -3
- data/lib/dry/schema/key_validator.rb +2 -2
- data/lib/dry/schema/macros/core.rb +2 -2
- data/lib/dry/schema/macros/dsl.rb +8 -4
- data/lib/dry/schema/macros/key.rb +0 -1
- data/lib/dry/schema/messages/yaml.rb +1 -1
- data/lib/dry/schema/result.rb +2 -0
- data/lib/dry/schema/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ee230572b92457f6619423c9963be605d79e86cfb4cef112767eda78e5223d
|
4
|
+
data.tar.gz: e9584df52d3c640691168703536546654a97eec2960fc96d932ea69ba5cedc50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4fa2334f3093e9a18ecea268e8f977204d40104f93c3db75c23bd82001b8b0636f9d8a4053f101b94e7a73982b5bdee67e65b5de13e7709bc1893f3a6c01061
|
7
|
+
data.tar.gz: 2ae6ef323db1a53ae6c375d2bdf1986379aacf5627385394549d784463fc6ebe621bcaaf73b391aa719661e66d47a7a52fd90b5539fe68e681fa4d90e268f2ca
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.13.2 2023-05-31
|
4
|
+
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- Fix custom predicates setting (via #460) (@solnic)
|
9
|
+
|
10
|
+
|
11
|
+
[Compare v1.13.1...v1.13.2](https://github.com/dry-rb/dry-schema/compare/v1.13.1...v1.13.2)
|
12
|
+
|
13
|
+
## 1.13.1 2023-04-07
|
14
|
+
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
- Support sum types of hashes (issue #446 fixed via #457) (@segiddins)
|
19
|
+
|
20
|
+
|
21
|
+
[Compare v1.13.0...v1.13.1](https://github.com/dry-rb/dry-schema/compare/v1.13.0...v1.13.1)
|
22
|
+
|
3
23
|
## 1.13.0 2022-11-24
|
4
24
|
|
5
25
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[gem]: https://rubygems.org/gems/dry-schema
|
3
3
|
[actions]: https://github.com/dry-rb/dry-schema/actions
|
4
4
|
|
5
|
-
# dry-schema [][gem] [][gem] [][actions]
|
6
6
|
|
7
7
|
## Links
|
8
8
|
|
@@ -14,8 +14,8 @@
|
|
14
14
|
|
15
15
|
This library officially supports the following Ruby versions:
|
16
16
|
|
17
|
-
* MRI `>=
|
18
|
-
* jruby `>= 9.
|
17
|
+
* MRI `>= 3.0.0`
|
18
|
+
* jruby `>= 9.4` (not tested on CI)
|
19
19
|
|
20
20
|
## License
|
21
21
|
|
data/dry-schema.gemspec
CHANGED
@@ -31,14 +31,14 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-schema"
|
32
32
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-schema/issues"
|
33
33
|
|
34
|
-
spec.required_ruby_version = ">= 2.7
|
34
|
+
spec.required_ruby_version = ">= 2.7"
|
35
35
|
|
36
36
|
# to update dependencies edit project.yml
|
37
37
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
38
38
|
spec.add_runtime_dependency "dry-configurable", "~> 1.0", ">= 1.0.1"
|
39
39
|
spec.add_runtime_dependency "dry-core", "~> 1.0", "< 2"
|
40
40
|
spec.add_runtime_dependency "dry-initializer", "~> 3.0"
|
41
|
-
spec.add_runtime_dependency "dry-logic", ">= 1.
|
41
|
+
spec.add_runtime_dependency "dry-logic", ">= 1.4", "< 2"
|
42
42
|
spec.add_runtime_dependency "dry-types", ">= 1.7", "< 2"
|
43
43
|
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
44
44
|
|
data/lib/dry/schema/config.rb
CHANGED
@@ -22,7 +22,9 @@ module Dry
|
|
22
22
|
# @return [Schema::PredicateRegistry]
|
23
23
|
#
|
24
24
|
# @api public
|
25
|
-
setting :predicates, default:
|
25
|
+
setting :predicates, default: PredicateRegistry.new, constructor: -> predicates {
|
26
|
+
predicates.is_a?(PredicateRegistry) ? predicates : PredicateRegistry.new(predicates)
|
27
|
+
}
|
26
28
|
|
27
29
|
# @!method types
|
28
30
|
#
|
data/lib/dry/schema/dsl.rb
CHANGED
@@ -39,9 +39,6 @@ module Dry
|
|
39
39
|
|
40
40
|
extend Dry::Initializer
|
41
41
|
|
42
|
-
# @return [Compiler] The rule compiler object
|
43
|
-
option :compiler, default: -> { Compiler.new }
|
44
|
-
|
45
42
|
# @return [Compiler] The type of the processor (Params, JSON, or a custom sub-class)
|
46
43
|
option :processor_type, default: -> { Processor }
|
47
44
|
|
@@ -84,6 +81,7 @@ module Dry
|
|
84
81
|
def self.new(**options, &block)
|
85
82
|
dsl = super
|
86
83
|
dsl.instance_eval(&block) if block
|
84
|
+
dsl.instance_variable_set("@compiler", options[:compiler]) if options[:compiler]
|
87
85
|
dsl
|
88
86
|
end
|
89
87
|
|
@@ -106,6 +104,16 @@ module Dry
|
|
106
104
|
self
|
107
105
|
end
|
108
106
|
|
107
|
+
# @api private
|
108
|
+
def compiler
|
109
|
+
@compiler ||= Compiler.new(predicates)
|
110
|
+
end
|
111
|
+
|
112
|
+
# @api private
|
113
|
+
def predicates
|
114
|
+
@predicates ||= config.predicates
|
115
|
+
end
|
116
|
+
|
109
117
|
# Return a macro with the provided name
|
110
118
|
#
|
111
119
|
# @param [Symbol] name
|
@@ -293,8 +301,8 @@ module Dry
|
|
293
301
|
# @return [Dry::Types::Safe]
|
294
302
|
#
|
295
303
|
# @api private
|
296
|
-
def new(**options, &block)
|
297
|
-
|
304
|
+
def new(klass: self.class, **options, &block)
|
305
|
+
klass.new(**options, processor_type: processor_type, config: config, &block)
|
298
306
|
end
|
299
307
|
|
300
308
|
# Set a type for the given key name
|
@@ -5,20 +5,42 @@ require "dry/struct"
|
|
5
5
|
module Dry
|
6
6
|
module Schema
|
7
7
|
module Macros
|
8
|
+
class StructToSchema < ::Dry::Struct::Compiler
|
9
|
+
def call(struct)
|
10
|
+
visit(struct.to_ast)
|
11
|
+
end
|
12
|
+
|
13
|
+
# strip away structs from AST
|
14
|
+
def visit_struct(node)
|
15
|
+
_, ast = node
|
16
|
+
visit(ast)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Hash.option :struct_compiler, default: proc { StructToSchema.new(schema_dsl.config.types) }
|
21
|
+
|
8
22
|
Hash.prepend(::Module.new {
|
9
23
|
def call(*args)
|
10
|
-
if args.size >= 1 &&
|
24
|
+
if args.size >= 1 && struct?(args[0])
|
11
25
|
if block_given?
|
12
26
|
raise ArgumentError, "blocks are not supported when using "\
|
13
27
|
"a struct class (#{name.inspect} => #{args[0]})"
|
14
28
|
end
|
15
29
|
|
16
|
-
|
17
|
-
|
30
|
+
schema = struct_compiler.(args[0])
|
31
|
+
|
32
|
+
super(schema, *args.drop(1))
|
33
|
+
type(schema_dsl.types[name].constructor(schema))
|
18
34
|
else
|
19
35
|
super
|
20
36
|
end
|
21
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def struct?(type)
|
42
|
+
type.is_a?(::Class) && type <= ::Dry::Struct
|
43
|
+
end
|
22
44
|
})
|
23
45
|
end
|
24
46
|
|
@@ -19,10 +19,10 @@ module Dry
|
|
19
19
|
option :compiler, default: proc { Compiler.new }
|
20
20
|
|
21
21
|
# @api private
|
22
|
-
option :
|
22
|
+
option :schema_dsl, optional: true
|
23
23
|
|
24
24
|
# @api private
|
25
|
-
option :
|
25
|
+
option :trace, default: proc { Trace.new(schema_dsl&.compiler || Compiler.new) }
|
26
26
|
|
27
27
|
# @api private
|
28
28
|
def new(**options)
|
@@ -122,7 +122,6 @@ module Dry
|
|
122
122
|
macro.call(...)
|
123
123
|
end
|
124
124
|
end
|
125
|
-
ruby2_keywords :schema if respond_to?(:ruby2_keywords, true)
|
126
125
|
|
127
126
|
# Specify a nested hash with enforced `hash?` type-check
|
128
127
|
#
|
@@ -137,7 +136,6 @@ module Dry
|
|
137
136
|
macro.call(...)
|
138
137
|
end
|
139
138
|
end
|
140
|
-
ruby2_keywords :hash if respond_to?(:ruby2_keywords, true)
|
141
139
|
|
142
140
|
# Specify predicates that should be applied to each element of an array
|
143
141
|
#
|
@@ -161,7 +159,6 @@ module Dry
|
|
161
159
|
macro.value(...)
|
162
160
|
end
|
163
161
|
end
|
164
|
-
ruby2_keywords :each if respond_to?(:ruby2_keywords, true)
|
165
162
|
|
166
163
|
# Like `each` but sets `array?` type-check
|
167
164
|
#
|
@@ -181,7 +178,6 @@ module Dry
|
|
181
178
|
macro.value(...)
|
182
179
|
end
|
183
180
|
end
|
184
|
-
ruby2_keywords :array if respond_to?(:ruby2_keywords, true)
|
185
181
|
|
186
182
|
# Set type spec
|
187
183
|
#
|
@@ -220,6 +216,8 @@ module Dry
|
|
220
216
|
end
|
221
217
|
|
222
218
|
# @api private
|
219
|
+
# rubocop: disable Metrics/AbcSize
|
220
|
+
# rubocop: disable Metrics/CyclomaticComplexity
|
223
221
|
# rubocop: disable Metrics/PerceivedComplexity
|
224
222
|
def extract_type_spec(args, nullable: false, set_type: true)
|
225
223
|
type_spec = args[0] unless schema_or_predicate?(args[0])
|
@@ -232,6 +230,10 @@ module Dry
|
|
232
230
|
|
233
231
|
if type_spec.is_a?(::Array)
|
234
232
|
type_rule = type_spec.map { |ts| new(chain: false).value(ts) }.reduce(:|)
|
233
|
+
elsif type_spec.is_a?(Dry::Types::Sum) && set_type
|
234
|
+
type_rule = [type_spec.left, type_spec.right].map { |ts|
|
235
|
+
new(klass: Core, chain: false).value(ts)
|
236
|
+
}.reduce(:|)
|
235
237
|
else
|
236
238
|
type_predicates = predicate_inferrer[resolved_type]
|
237
239
|
|
@@ -249,6 +251,8 @@ module Dry
|
|
249
251
|
yield(*predicates, type_spec: type_spec, type_rule: nil)
|
250
252
|
end
|
251
253
|
end
|
254
|
+
# rubocop: enable Metrics/AbcSize
|
255
|
+
# rubocop: enable Metrics/CyclomaticComplexity
|
252
256
|
# rubocop: enable Metrics/PerceivedComplexity
|
253
257
|
|
254
258
|
# @api private
|
data/lib/dry/schema/result.rb
CHANGED
data/lib/dry/schema/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.13.
|
4
|
+
version: 1.13.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -84,7 +84,7 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '1.
|
87
|
+
version: '1.4'
|
88
88
|
- - "<"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '2'
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
requirements:
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '1.
|
97
|
+
version: '1.4'
|
98
98
|
- - "<"
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '2'
|
@@ -274,14 +274,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
274
|
requirements:
|
275
275
|
- - ">="
|
276
276
|
- !ruby/object:Gem::Version
|
277
|
-
version: 2.7
|
277
|
+
version: '2.7'
|
278
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
279
|
requirements:
|
280
280
|
- - ">="
|
281
281
|
- !ruby/object:Gem::Version
|
282
282
|
version: '0'
|
283
283
|
requirements: []
|
284
|
-
rubygems_version: 3.
|
284
|
+
rubygems_version: 3.3.26
|
285
285
|
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Coercion and validation for data structures
|