dry-validation 1.7.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +4 -4
- data/dry-validation.gemspec +2 -2
- data/lib/dry/validation/contract/class_interface.rb +5 -3
- data/lib/dry/validation/contract.rb +2 -0
- data/lib/dry/validation/evaluator.rb +11 -2
- data/lib/dry/validation/function.rb +1 -2
- data/lib/dry/validation/macro.rb +1 -1
- data/lib/dry/validation/message.rb +2 -0
- data/lib/dry/validation/messages/resolver.rb +4 -6
- data/lib/dry/validation/result.rb +7 -0
- data/lib/dry/validation/rule.rb +4 -1
- data/lib/dry/validation/values.rb +2 -1
- data/lib/dry/validation/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cbb33c9bad218b481c727b04080736ad0d974f47b552ed305de4f50e5bd8d6d
|
4
|
+
data.tar.gz: e464d56a10afa52ab975d44d204a0879649007eeb98a1a15038e5c6d29b78b21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94637a8714ffc4111c0279a7aeb52613fccf894abd33207600131e7af59803371b044691949c9a457c85bbdbb9d063c7c050aa58fc51966e7469b62f97156008
|
7
|
+
data.tar.gz: f15fbb334bd99fe79348a750bca344beff68156394c314f1845307a1b5b2462446117a80e47d0d3eb40108e3042de99744c205a7ffc99ef48bebd179a5fa0299
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.8.1 2022-05-28
|
4
|
+
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- Raise an InvalidKeyErrors on substring of valid keys (issue #705 fixed via #706) (@MatElGran)
|
9
|
+
- Using `rule(:arr).each { .. }` doesn't crash when `:arr` turns out to be `nil` (issue #708 fixed via #709) (@bautrey37)
|
10
|
+
|
11
|
+
|
12
|
+
[Compare v1.8.0...v1.8.1](https://github.com/dry-rb/dry-validation/compare/v1.8.0...v1.8.1)
|
13
|
+
|
14
|
+
## 1.8.0 2022-02-17
|
15
|
+
|
16
|
+
|
17
|
+
### Added
|
18
|
+
|
19
|
+
- New rule helper `base_rule_error?` which checks if there's any base error set (via #690) (@wuarmin)
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- Dependency on dry-schema was bumped to 1.9.1 (@solnic)
|
24
|
+
|
25
|
+
[Compare v1.7.0...v1.8.0](https://github.com/dry-rb/dry-validation/compare/v1.7.0...v1.8.0)
|
26
|
+
|
3
27
|
## 1.7.0 2021-09-12
|
4
28
|
|
5
29
|
|
data/README.md
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
# dry-validation [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
|
9
9
|
|
10
10
|
[![Gem Version](https://badge.fury.io/rb/dry-validation.svg)][gem]
|
11
|
-
[![CI Status](https://github.com/dry-rb/dry-validation/workflows/
|
11
|
+
[![CI Status](https://github.com/dry-rb/dry-validation/workflows/ci/badge.svg)][actions]
|
12
12
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f30e3ff5ec304c55a73868cdbf055c67)][codacy]
|
13
13
|
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f30e3ff5ec304c55a73868cdbf055c67)][codacy]
|
14
|
-
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-validation.svg?branch=
|
14
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-validation.svg?branch=main)][inchpages]
|
15
15
|
|
16
16
|
## Links
|
17
17
|
|
@@ -22,8 +22,8 @@
|
|
22
22
|
|
23
23
|
This library officially supports the following Ruby versions:
|
24
24
|
|
25
|
-
* MRI `>= 2.
|
26
|
-
*
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
27
27
|
|
28
28
|
## License
|
29
29
|
|
data/dry-validation.gemspec
CHANGED
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
-
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-validation/blob/
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-validation/blob/main/CHANGELOG.md"
|
26
26
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-validation"
|
27
27
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-validation/issues"
|
28
28
|
|
29
|
-
spec.required_ruby_version = ">= 2.
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
30
30
|
|
31
31
|
# to update dependencies edit project.yml
|
32
32
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
@@ -158,11 +158,13 @@ module Dry
|
|
158
158
|
valid_paths = key_map.to_dot_notation
|
159
159
|
key_paths = key_paths(keys)
|
160
160
|
|
161
|
-
invalid_keys = key_paths.
|
162
|
-
|
161
|
+
invalid_keys = key_paths.filter_map { |(key, path)|
|
162
|
+
if valid_paths.none? { |vp|
|
163
|
+
vp == path || vp.start_with?("#{path}.", "#{path}[]")
|
164
|
+
}
|
163
165
|
key
|
164
166
|
end
|
165
|
-
}.
|
167
|
+
}.uniq
|
166
168
|
|
167
169
|
return if invalid_keys.empty?
|
168
170
|
|
@@ -96,6 +96,7 @@ module Dry
|
|
96
96
|
# @return [Result]
|
97
97
|
#
|
98
98
|
# @api public
|
99
|
+
# rubocop: disable Metrics/AbcSize
|
99
100
|
def call(input, context = EMPTY_HASH)
|
100
101
|
context_map = Concurrent::Map.new.tap do |map|
|
101
102
|
default_context.each { |key, value| map[key] = value }
|
@@ -114,6 +115,7 @@ module Dry
|
|
114
115
|
end
|
115
116
|
end
|
116
117
|
end
|
118
|
+
# rubocop: enable Metrics/AbcSize
|
117
119
|
|
118
120
|
# Return a nice string representation
|
119
121
|
#
|
@@ -17,7 +17,7 @@ module Dry
|
|
17
17
|
# @api public
|
18
18
|
class Evaluator
|
19
19
|
extend Dry::Initializer
|
20
|
-
extend Dry::Core::Deprecations[:
|
20
|
+
extend Dry::Core::Deprecations[:"dry-validation"]
|
21
21
|
|
22
22
|
deprecate :error?, :schema_error?
|
23
23
|
|
@@ -73,7 +73,7 @@ module Dry
|
|
73
73
|
@_options = options
|
74
74
|
|
75
75
|
if block
|
76
|
-
exec_opts = block_options.
|
76
|
+
exec_opts = block_options.transform_values { _options[_1] }
|
77
77
|
instance_exec(**exec_opts, &block)
|
78
78
|
end
|
79
79
|
|
@@ -200,6 +200,15 @@ module Dry
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
+
# Check if there are any base rule errors
|
204
|
+
#
|
205
|
+
# @return [Boolean]
|
206
|
+
#
|
207
|
+
# @api public
|
208
|
+
def base_rule_error?
|
209
|
+
!base.empty? || result.base_rule_error?
|
210
|
+
end
|
211
|
+
|
203
212
|
# @api private
|
204
213
|
def respond_to_missing?(meth, include_private = false)
|
205
214
|
super || _contract.respond_to?(meth, true)
|
data/lib/dry/validation/macro.rb
CHANGED
@@ -70,11 +70,13 @@ module Dry
|
|
70
70
|
# Initialize a new error object
|
71
71
|
#
|
72
72
|
# @api private
|
73
|
+
# rubocop: disable Lint/MissingSuper
|
73
74
|
def initialize(text, path:, meta: EMPTY_HASH)
|
74
75
|
@text = text
|
75
76
|
@path = Array(path)
|
76
77
|
@meta = meta
|
77
78
|
end
|
79
|
+
# rubocop: enable Lint/MissingSuper
|
78
80
|
|
79
81
|
# Check if this is a base error not associated with any key
|
80
82
|
#
|
@@ -61,7 +61,8 @@ module Dry
|
|
61
61
|
# @api public
|
62
62
|
#
|
63
63
|
# rubocop:disable Metrics/AbcSize
|
64
|
-
|
64
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
65
|
+
def message(rule, path:, tokens: EMPTY_HASH, locale: nil, full: false)
|
65
66
|
keys = path.to_a.compact
|
66
67
|
msg_opts = tokens.merge(path: keys, locale: locale || messages.default_locale)
|
67
68
|
|
@@ -88,6 +89,7 @@ module Dry
|
|
88
89
|
|
89
90
|
[message_text(text, path: path, locale: locale, full: full), meta]
|
90
91
|
end
|
92
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
91
93
|
# rubocop:enable Metrics/AbcSize
|
92
94
|
|
93
95
|
private
|
@@ -110,11 +112,7 @@ module Dry
|
|
110
112
|
end
|
111
113
|
|
112
114
|
def parse_tokens(tokens)
|
113
|
-
|
114
|
-
tokens.map do |key, token|
|
115
|
-
[key, parse_token(token)]
|
116
|
-
end
|
117
|
-
]
|
115
|
+
tokens.transform_values { parse_token(_1) }
|
118
116
|
end
|
119
117
|
|
120
118
|
def parse_token(token)
|
@@ -120,6 +120,13 @@ module Dry
|
|
120
120
|
!schema_error?(key) && error?(key)
|
121
121
|
end
|
122
122
|
|
123
|
+
# Check if the result contains any base rule errors
|
124
|
+
#
|
125
|
+
# @api private
|
126
|
+
def base_rule_error?
|
127
|
+
!errors.filter(:base?).empty?
|
128
|
+
end
|
129
|
+
|
123
130
|
# Check if there's any error for the provided key
|
124
131
|
#
|
125
132
|
# This does not consider errors from the nested values
|
data/lib/dry/validation/rule.rb
CHANGED
@@ -76,13 +76,15 @@ module Dry
|
|
76
76
|
# @return [Rule]
|
77
77
|
#
|
78
78
|
# @api public
|
79
|
+
#
|
80
|
+
# rubocop:disable Metrics/AbcSize
|
79
81
|
def each(*macros, &block)
|
80
82
|
root = keys[0]
|
81
83
|
macros = parse_macros(*macros)
|
82
84
|
@keys = []
|
83
85
|
|
84
86
|
@block = proc do
|
85
|
-
unless result.base_error?(root) || !values.key?(root)
|
87
|
+
unless result.base_error?(root) || !values.key?(root) || values[root].nil?
|
86
88
|
values[root].each_with_index do |_, idx|
|
87
89
|
path = [*Schema::Path[root].to_a, idx]
|
88
90
|
|
@@ -99,6 +101,7 @@ module Dry
|
|
99
101
|
|
100
102
|
self
|
101
103
|
end
|
104
|
+
# rubocop:enable Metrics/AbcSize
|
102
105
|
|
103
106
|
# Return a nice string representation
|
104
107
|
#
|
@@ -61,6 +61,7 @@ module Dry
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# @api public
|
64
|
+
# rubocop: disable Metrics/PerceivedComplexity
|
64
65
|
def key?(key, hash = data)
|
65
66
|
return hash.key?(key) if key.is_a?(Symbol)
|
66
67
|
|
@@ -79,9 +80,9 @@ module Dry
|
|
79
80
|
end
|
80
81
|
a[e]
|
81
82
|
end
|
82
|
-
|
83
83
|
true
|
84
84
|
end
|
85
|
+
# rubocop: enable Metrics/PerceivedComplexity
|
85
86
|
|
86
87
|
# @api private
|
87
88
|
def respond_to_missing?(meth, include_private = false)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -179,10 +179,10 @@ licenses:
|
|
179
179
|
- MIT
|
180
180
|
metadata:
|
181
181
|
allowed_push_host: https://rubygems.org
|
182
|
-
changelog_uri: https://github.com/dry-rb/dry-validation/blob/
|
182
|
+
changelog_uri: https://github.com/dry-rb/dry-validation/blob/main/CHANGELOG.md
|
183
183
|
source_code_uri: https://github.com/dry-rb/dry-validation
|
184
184
|
bug_tracker_uri: https://github.com/dry-rb/dry-validation/issues
|
185
|
-
post_install_message:
|
185
|
+
post_install_message:
|
186
186
|
rdoc_options: []
|
187
187
|
require_paths:
|
188
188
|
- lib
|
@@ -190,15 +190,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
190
|
requirements:
|
191
191
|
- - ">="
|
192
192
|
- !ruby/object:Gem::Version
|
193
|
-
version: 2.
|
193
|
+
version: 2.7.0
|
194
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
195
|
requirements:
|
196
196
|
- - ">="
|
197
197
|
- !ruby/object:Gem::Version
|
198
198
|
version: '0'
|
199
199
|
requirements: []
|
200
|
-
rubygems_version: 3.
|
201
|
-
signing_key:
|
200
|
+
rubygems_version: 3.2.32
|
201
|
+
signing_key:
|
202
202
|
specification_version: 4
|
203
203
|
summary: Validation library
|
204
204
|
test_files: []
|