dry-schema 1.13.1 → 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 +10 -0
- data/README.md +1 -1
- data/lib/dry/schema/config.rb +3 -1
- data/lib/dry/schema/dsl.rb +11 -3
- 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/version.rb +1 -1
- metadata +2 -2
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,15 @@
|
|
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
|
+
|
3
13
|
## 1.13.1 2023-04-07
|
4
14
|
|
5
15
|
|
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
|
|
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
|
@@ -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)
|
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: 2023-
|
11
|
+
date: 2023-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|