dry-schema 1.16.0 → 1.17.0
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 +36 -3
- data/README.md +6 -1
- data/dry-schema.gemspec +1 -2
- data/lib/dry/schema/config.rb +5 -0
- data/lib/dry/schema/dsl.rb +2 -2
- data/lib/dry/schema/macros/dsl.rb +24 -7
- data/lib/dry/schema/macros/key.rb +1 -1
- data/lib/dry/schema/macros/value.rb +1 -1
- data/lib/dry/schema/message/or/multi_path.rb +1 -1
- data/lib/dry/schema/messages.rb +36 -5
- data/lib/dry/schema/trace.rb +1 -1
- data/lib/dry/schema/version.rb +1 -1
- data/lib/dry/schema.rb +3 -3
- metadata +2 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b54511171dc7fabc01aadfd9a1fd2be49ba597ca0210996f31567b7497360ac
|
|
4
|
+
data.tar.gz: 01bba0206f064be19b2f8b8048e326890f8bca3e359b59d2f0664d12a57c9e4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 24b64bb68fa2b0494b7e78e4add7bb1155986b801862cca1abdf5b79c0697778e5d3456033c99574a93ae55638318bdb6a69b758b983d3b542b06313cc17b621
|
|
7
|
+
data.tar.gz: 7072a8dca2e49ca412da5bd5923fd906e8cda76f7234f4269797fcd807d2a577978b9cdcb6a7a517f4ccad9558eace9a9fe954b6a33956b9071681aaa2499781
|
data/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
|
|
7
6
|
|
|
8
7
|
## [Unreleased]
|
|
9
8
|
|
|
@@ -19,7 +18,41 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve
|
|
|
19
18
|
|
|
20
19
|
### Security
|
|
21
20
|
|
|
22
|
-
[Unreleased]: https://github.com/dry-rb/dry-schema/compare/v1.
|
|
21
|
+
[Unreleased]: https://github.com/dry-rb/dry-schema/compare/v1.17.0...main
|
|
22
|
+
|
|
23
|
+
## [1.17.0] - 2026-11-20
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Accept predicate keywords without a question mark, matching dry-types constraints. Keywords with a question mark still work. (@aaronmallen in #520)
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
Dry::Schema.Params do
|
|
31
|
+
required(:name).filled(:string, min_size: 2)
|
|
32
|
+
required(:age).value(:integer, gt: 18)
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
- Accept a custom messages backend for `config.messages.backend`: a `Dry::Schema::Messages::Abstract` subclass, or any object responding to `build(options)`. (@parndt in #526)
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
class ShoutingMessages < Dry::Schema::Messages::YAML
|
|
39
|
+
def get(key, options = EMPTY_HASH)
|
|
40
|
+
result = super
|
|
41
|
+
result&.merge(text: result[:text].upcase)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
schema = Dry::Schema.define do
|
|
46
|
+
config.messages.backend = ShoutingMessages
|
|
47
|
+
|
|
48
|
+
required(:name).filled(:string)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
schema.(name: "").errors.to_h
|
|
52
|
+
# => {name: ["MUST BE FILLED"]}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
[1.17.0]: https://github.com/dry-rb/dry-schema/compare/v1.16.0...v1.17.0
|
|
23
56
|
|
|
24
57
|
## [1.16.0] - 2026-03-03
|
|
25
58
|
|
data/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
<!--- This file is synced from hanakai-rb/repo-sync -->
|
|
2
2
|
|
|
3
|
-
[rubygem]: https://rubygems.org/gems/dry-schema
|
|
4
3
|
[actions]: https://github.com/dry-rb/dry-schema/actions
|
|
4
|
+
[chat]: https://discord.gg/naQApPAsZB
|
|
5
|
+
[forum]: https://discourse.hanakai.org
|
|
6
|
+
[rubygem]: https://rubygems.org/gems/dry-schema
|
|
5
7
|
|
|
6
8
|
# dry-schema [][rubygem] [][actions]
|
|
7
9
|
|
|
10
|
+
[][forum]
|
|
11
|
+
[][chat]
|
|
12
|
+
|
|
8
13
|
## Links
|
|
9
14
|
|
|
10
15
|
- [User documentation](https://dry-rb.org/gems/dry-schema)
|
data/dry-schema.gemspec
CHANGED
|
@@ -27,13 +27,12 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
|
|
28
28
|
spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
|
|
29
29
|
|
|
30
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
31
30
|
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-schema/blob/main/CHANGELOG.md"
|
|
32
31
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-schema"
|
|
33
32
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-schema/issues"
|
|
34
33
|
spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
|
|
35
34
|
|
|
36
|
-
spec.required_ruby_version = ">= 3.
|
|
35
|
+
spec.required_ruby_version = ">= 3.3"
|
|
37
36
|
|
|
38
37
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
|
39
38
|
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
data/lib/dry/schema/config.rb
CHANGED
|
@@ -39,6 +39,11 @@ module Dry
|
|
|
39
39
|
#
|
|
40
40
|
# Return configuration for message backend
|
|
41
41
|
#
|
|
42
|
+
# `backend` is `:yaml` (the default), `:i18n`, or an object that responds to
|
|
43
|
+
# `build(options)`, such as a subclass of {Messages::Abstract}. A custom backend's `build`
|
|
44
|
+
# receives only the options for settings defined on {Messages::Abstract}, so settings that a
|
|
45
|
+
# subclass adds keep their defaults unless the subclass sets them.
|
|
46
|
+
#
|
|
42
47
|
# @return [Dry::Configurable::Config]
|
|
43
48
|
#
|
|
44
49
|
# @api public
|
data/lib/dry/schema/dsl.rb
CHANGED
|
@@ -132,7 +132,7 @@ module Dry
|
|
|
132
132
|
#
|
|
133
133
|
# required(:age).value(:integer)
|
|
134
134
|
#
|
|
135
|
-
# required(:user_limit).value(:integer, gt
|
|
135
|
+
# required(:user_limit).value(:integer, gt: 0)
|
|
136
136
|
#
|
|
137
137
|
# required(:tags).filled { array? | str? }
|
|
138
138
|
#
|
|
@@ -502,7 +502,7 @@ module Dry
|
|
|
502
502
|
parents.each_cons(2) do |left, right|
|
|
503
503
|
unless left.config == right.config
|
|
504
504
|
raise ::ArgumentError,
|
|
505
|
-
|
|
505
|
+
"Parent configs differ, left=#{left.inspect}, right=#{right.inspect}"
|
|
506
506
|
end
|
|
507
507
|
end
|
|
508
508
|
|
|
@@ -13,6 +13,16 @@ module Dry
|
|
|
13
13
|
undef :nil?
|
|
14
14
|
undef :respond_to?
|
|
15
15
|
|
|
16
|
+
# Keyword options that macros read for themselves, rather than treating them as predicates
|
|
17
|
+
#
|
|
18
|
+
# These must never share a name with a built-in predicate (minus its question mark), since
|
|
19
|
+
# predicate keywords may be written without the question mark. A custom predicate that
|
|
20
|
+
# shares one of these names can still be used by including its question mark, e.g.
|
|
21
|
+
# `type_rule?: 1`.
|
|
22
|
+
#
|
|
23
|
+
# @api private
|
|
24
|
+
MACRO_OPTIONS = %i[type_spec type_rule].freeze
|
|
25
|
+
|
|
16
26
|
# @!attribute [r] chain
|
|
17
27
|
# Indicate if the macro should append its rules to the provided trace
|
|
18
28
|
# @return [Boolean]
|
|
@@ -34,6 +44,10 @@ module Dry
|
|
|
34
44
|
# @overload value(*predicates, **predicate_opts)
|
|
35
45
|
# Set predicates without and with arguments
|
|
36
46
|
#
|
|
47
|
+
# Predicates with arguments may be given as keywords, with or without their question
|
|
48
|
+
# mark: `min_size: 2` and `min_size?: 2` are the same. Including the question mark is
|
|
49
|
+
# always unambiguous, so use it if a predicate name could clash with a macro option.
|
|
50
|
+
#
|
|
37
51
|
# @param [Array<Symbol>] predicates
|
|
38
52
|
# @param [Hash] predicate_opts
|
|
39
53
|
#
|
|
@@ -41,10 +55,13 @@ module Dry
|
|
|
41
55
|
# required(:name).value(:filled?)
|
|
42
56
|
#
|
|
43
57
|
# @example with a predicate with arguments
|
|
44
|
-
# required(:name).value(min_size
|
|
58
|
+
# required(:name).value(min_size: 2)
|
|
45
59
|
#
|
|
46
60
|
# @example with a predicate with and without arguments
|
|
47
|
-
# required(:name).value(:filled?, min_size
|
|
61
|
+
# required(:name).value(:filled?, min_size: 2)
|
|
62
|
+
#
|
|
63
|
+
# @example with a predicate name that includes its question mark
|
|
64
|
+
# required(:name).value(min_size?: 2)
|
|
48
65
|
#
|
|
49
66
|
# @example with a block
|
|
50
67
|
# required(:name).value { filled? & min_size?(2) }
|
|
@@ -72,7 +89,7 @@ module Dry
|
|
|
72
89
|
# required(:name).filled(:string)
|
|
73
90
|
#
|
|
74
91
|
# @example with a type spec and a predicate
|
|
75
|
-
# required(:name).filled(:string, format
|
|
92
|
+
# required(:name).filled(:string, format: /\w+/)
|
|
76
93
|
#
|
|
77
94
|
# @return [Macros::Core]
|
|
78
95
|
#
|
|
@@ -110,7 +127,7 @@ module Dry
|
|
|
110
127
|
# manually.
|
|
111
128
|
#
|
|
112
129
|
# @example
|
|
113
|
-
# required(:tags).value(:hash, min_size
|
|
130
|
+
# required(:tags).value(:hash, min_size: 1).schema do
|
|
114
131
|
# required(:name).value(:string)
|
|
115
132
|
# end
|
|
116
133
|
#
|
|
@@ -144,10 +161,10 @@ module Dry
|
|
|
144
161
|
# manually.
|
|
145
162
|
#
|
|
146
163
|
# @example a list of strings
|
|
147
|
-
# required(:tags).value(:array, min_size
|
|
164
|
+
# required(:tags).value(:array, min_size: 2).each(:str?)
|
|
148
165
|
#
|
|
149
166
|
# @example a list of hashes
|
|
150
|
-
# required(:tags).value(:array, min_size
|
|
167
|
+
# required(:tags).value(:array, min_size: 2).each(:hash) do
|
|
151
168
|
# required(:name).filled(:string)
|
|
152
169
|
# end
|
|
153
170
|
#
|
|
@@ -182,7 +199,7 @@ module Dry
|
|
|
182
199
|
# Set type spec
|
|
183
200
|
#
|
|
184
201
|
# @example
|
|
185
|
-
# required(:name).type(:string).value(min_size
|
|
202
|
+
# required(:name).type(:string).value(min_size: 2)
|
|
186
203
|
#
|
|
187
204
|
# @param [Symbol, Array, Dry::Types::Type] spec
|
|
188
205
|
#
|
|
@@ -15,7 +15,7 @@ module Dry
|
|
|
15
15
|
# Specify predicates that should be applied before coercion
|
|
16
16
|
#
|
|
17
17
|
# @example check format before coercing to a date
|
|
18
|
-
# required(:publish_date).filter(format
|
|
18
|
+
# required(:publish_date).filter(format: /\d{4}-\d{2}-\d{2}).value(:date)
|
|
19
19
|
#
|
|
20
20
|
# @see Macros::Key#value
|
|
21
21
|
#
|
data/lib/dry/schema/messages.rb
CHANGED
|
@@ -14,19 +14,50 @@ module Dry
|
|
|
14
14
|
module_function
|
|
15
15
|
|
|
16
16
|
public def setup(config)
|
|
17
|
-
backend_class = BACKENDS.fetch(config.backend) do
|
|
18
|
-
raise "+#{config.backend}+ is not a valid messages identifier"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
17
|
namespace = config.namespace
|
|
22
18
|
options = config.to_h.select { |k, _| Abstract.setting_names.include?(k) }
|
|
23
19
|
|
|
24
|
-
messages =
|
|
20
|
+
messages = backend(config.backend).build(options)
|
|
25
21
|
|
|
26
22
|
return messages.namespaced(namespace) if namespace
|
|
27
23
|
|
|
28
24
|
messages
|
|
29
25
|
end
|
|
26
|
+
|
|
27
|
+
# Returns the backend for the given identifier (`:i18n` or `:yaml`), or the given object
|
|
28
|
+
# itself if it can build messages, such as a subclass of {Abstract}
|
|
29
|
+
#
|
|
30
|
+
# The backend's `build` receives only the options for settings defined on {Abstract}. If a
|
|
31
|
+
# subclass adds its own settings, they keep their defaults unless the subclass sets them.
|
|
32
|
+
#
|
|
33
|
+
# A custom backend only needs `build(options)`, which must return an object that implements
|
|
34
|
+
# the {Abstract} interface. It does not need `#merge`.
|
|
35
|
+
#
|
|
36
|
+
# @api private
|
|
37
|
+
public def backend(identifier)
|
|
38
|
+
return identifier if identifier.respond_to?(:build)
|
|
39
|
+
|
|
40
|
+
backend_class = BACKENDS.fetch(identifier) do
|
|
41
|
+
raise invalid_backend_message(identifier)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
Messages.const_get(backend_class)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @api private
|
|
48
|
+
private_class_method def invalid_backend_message(identifier)
|
|
49
|
+
message =
|
|
50
|
+
"#{identifier.inspect} is not a valid messages backend. Use :yaml, :i18n, " \
|
|
51
|
+
"or an object that responds to #build, such as a subclass of #{Abstract}"
|
|
52
|
+
|
|
53
|
+
# It's an easy mistake to pass a pre-built messages object instead of its class, so add a
|
|
54
|
+
# hint for this case.
|
|
55
|
+
if identifier.is_a?(Abstract)
|
|
56
|
+
message += ". Pass the class (#{identifier.class}), not an instance."
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
message
|
|
60
|
+
end
|
|
30
61
|
end
|
|
31
62
|
end
|
|
32
63
|
end
|
data/lib/dry/schema/trace.rb
CHANGED
|
@@ -44,7 +44,7 @@ module Dry
|
|
|
44
44
|
elsif predicate.is_a?(::Array)
|
|
45
45
|
predicate.map { |pred| evaluate_predicates(pred).reduce(:&) }.reduce(:|)
|
|
46
46
|
elsif predicate.is_a?(::Hash)
|
|
47
|
-
predicate.map { |pred, *args| __send__(pred, *args) }
|
|
47
|
+
predicate.map { |pred, *args| __send__(:"#{pred.to_s.delete_suffix("?")}?", *args) }
|
|
48
48
|
else
|
|
49
49
|
__send__(predicate)
|
|
50
50
|
end
|
data/lib/dry/schema/version.rb
CHANGED
data/lib/dry/schema.rb
CHANGED
|
@@ -54,7 +54,7 @@ module Dry
|
|
|
54
54
|
# @example
|
|
55
55
|
# Dry::Schema.define do
|
|
56
56
|
# required(:name).filled(:string)
|
|
57
|
-
# required(:age).value(:integer, gt
|
|
57
|
+
# required(:age).value(:integer, gt: 0)
|
|
58
58
|
# end
|
|
59
59
|
#
|
|
60
60
|
# @param [Hash] options
|
|
@@ -75,7 +75,7 @@ module Dry
|
|
|
75
75
|
# @example
|
|
76
76
|
# Dry::Schema.Params do
|
|
77
77
|
# required(:name).filled(:string)
|
|
78
|
-
# required(:age).value(:integer, gt
|
|
78
|
+
# required(:age).value(:integer, gt: 0)
|
|
79
79
|
# end
|
|
80
80
|
#
|
|
81
81
|
# @return [Params]
|
|
@@ -95,7 +95,7 @@ module Dry
|
|
|
95
95
|
# @example
|
|
96
96
|
# Dry::Schema.JSON do
|
|
97
97
|
# required(:name).filled(:string)
|
|
98
|
-
# required(:age).value(:integer, gt
|
|
98
|
+
# required(:age).value(:integer, gt: 0)
|
|
99
99
|
# end
|
|
100
100
|
#
|
|
101
101
|
# @return [Params]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dry-schema
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hanakai team
|
|
@@ -265,7 +265,6 @@ homepage: https://dry-rb.org/gems/dry-schema
|
|
|
265
265
|
licenses:
|
|
266
266
|
- MIT
|
|
267
267
|
metadata:
|
|
268
|
-
allowed_push_host: https://rubygems.org
|
|
269
268
|
changelog_uri: https://github.com/dry-rb/dry-schema/blob/main/CHANGELOG.md
|
|
270
269
|
source_code_uri: https://github.com/dry-rb/dry-schema
|
|
271
270
|
bug_tracker_uri: https://github.com/dry-rb/dry-schema/issues
|
|
@@ -277,7 +276,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
277
276
|
requirements:
|
|
278
277
|
- - ">="
|
|
279
278
|
- !ruby/object:Gem::Version
|
|
280
|
-
version: '3.
|
|
279
|
+
version: '3.3'
|
|
281
280
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
282
281
|
requirements:
|
|
283
282
|
- - ">="
|