dry-validation 1.5.5 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -3
- data/LICENSE +1 -1
- data/README.md +4 -3
- data/dry-validation.gemspec +16 -16
- data/lib/dry/validation/config.rb +1 -1
- data/lib/dry/validation/contract.rb +16 -3
- data/lib/dry/validation/evaluator.rb +19 -4
- data/lib/dry/validation/function.rb +1 -2
- data/lib/dry/validation/macro.rb +1 -1
- data/lib/dry/validation/message.rb +3 -1
- data/lib/dry/validation/messages/resolver.rb +4 -6
- data/lib/dry/validation/result.rb +15 -1
- data/lib/dry/validation/rule.rb +1 -1
- data/lib/dry/validation/values.rb +9 -1
- data/lib/dry/validation/version.rb +1 -1
- metadata +19 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c0ec5ac402da094ae496a120274c13f2a251300df9b178adb0b688968687082
|
4
|
+
data.tar.gz: b07231e7542c689d1d02cf2e8de3837592cb7867cc7772c4968034129bb65012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d4835f01c7c8e02d63e1583f6e140efb8db33582800c2c276c94865f6841d8533b91b3fd5832944f57ad8e59f7660dcdff930dfe77e0ae17537c18f0caa14c6
|
7
|
+
data.tar.gz: e8b2cba4863b18461a8f64e6581654aecaca6525b603e40e6896199faecd5a735f8e5d1a8dbd9d6bb1ac43d562d8bb09ff3bbf77cd01d9b21d9cdef8da4f8e36
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,62 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## 1.8.0 2022-02-17
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- New rule helper `base_rule_error?` which checks if there's any base error set (via #690) (@wuarmin)
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Dependency on dry-schema was bumped to 1.9.1 (@solnic)
|
13
|
+
|
14
|
+
[Compare v1.7.0...v1.8.0](https://github.com/dry-rb/dry-validation/compare/v1.7.0...v1.8.0)
|
15
|
+
|
16
|
+
## 1.7.0 2021-09-12
|
17
|
+
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
|
21
|
+
- [internal] Upgraded to new `setting` API provided in dry-configurable 0.13.0 (@timriley in #686 and 3f8f7d8)
|
22
|
+
- Bumped dry-schema dependency to 1.8.0 (in part, to ensure dry-configurable 0.13.0 is available) (@timriley)
|
23
|
+
|
24
|
+
[Compare v1.6.0...v1.7.0](https://github.com/dry-rb/dry-validation/compare/v1.6.0...v1.7.0)
|
25
|
+
|
26
|
+
## 1.6.0 2020-12-05
|
27
|
+
|
28
|
+
|
29
|
+
### Added
|
30
|
+
|
31
|
+
- You can now pass a key name or path to `rule_error?` predicate (issue #658 closed via #673) (@moofkit)
|
32
|
+
- You can now pass initial context object to `Contract#call` (issue #674 via #675) (@pyromaniac)
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
- Checking `key?` within a rule no longer crashes when value is `nil` or an empty string (issue #670 fixed via #672) (@alexxty7)
|
37
|
+
|
38
|
+
|
39
|
+
[Compare v1.5.6...v1.6.0](https://github.com/dry-rb/dry-validation/compare/v1.5.6...v1.6.0)
|
40
|
+
|
41
|
+
## 1.5.6 2020-09-04
|
42
|
+
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
|
46
|
+
- Dependency on dry-schema was bumped to >= 1.5.1. This time for real (@solnic)
|
47
|
+
|
48
|
+
|
49
|
+
[Compare v1.5.5...v1.5.6](https://github.com/dry-rb/dry-validation/compare/v1.5.5...v1.5.6)
|
50
|
+
|
51
|
+
## 1.5.5 2020-09-03
|
2
52
|
|
3
|
-
2020-09-03
|
4
53
|
|
5
54
|
### Fixed
|
6
55
|
|
7
56
|
- Dependency on dry-schema was bumped to >= 1.5.2 (see #666 for more info) (@artofhuman)
|
8
57
|
|
9
58
|
|
10
|
-
[Compare v1.5.4...
|
59
|
+
[Compare v1.5.4...v1.5.5](https://github.com/dry-rb/dry-validation/compare/v1.5.4...v1.5.5)
|
11
60
|
|
12
61
|
## 1.5.4 2020-08-21
|
13
62
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
1
2
|
[gem]: https://rubygems.org/gems/dry-validation
|
2
3
|
[actions]: https://github.com/dry-rb/dry-validation/actions
|
3
4
|
[codacy]: https://www.codacy.com/gh/dry-rb/dry-validation
|
@@ -14,15 +15,15 @@
|
|
14
15
|
|
15
16
|
## Links
|
16
17
|
|
17
|
-
* [User documentation](
|
18
|
+
* [User documentation](https://dry-rb.org/gems/dry-validation)
|
18
19
|
* [API documentation](http://rubydoc.info/gems/dry-validation)
|
19
20
|
|
20
21
|
## Supported Ruby versions
|
21
22
|
|
22
23
|
This library officially supports the following Ruby versions:
|
23
24
|
|
24
|
-
* MRI
|
25
|
-
* jruby
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
26
27
|
|
27
28
|
## License
|
28
29
|
|
data/dry-validation.gemspec
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# this file is managed by dry-rb/devtools project
|
3
2
|
|
4
|
-
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
4
|
+
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
5
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require
|
7
|
+
require "dry/validation/version"
|
7
8
|
|
8
9
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
10
|
+
spec.name = "dry-validation"
|
10
11
|
spec.authors = ["Piotr Solnica"]
|
11
12
|
spec.email = ["piotr.solnica@gmail.com"]
|
12
|
-
spec.license =
|
13
|
+
spec.license = "MIT"
|
13
14
|
spec.version = Dry::Validation::VERSION.dup
|
14
15
|
|
15
16
|
spec.summary = "Validation library"
|
16
17
|
spec.description = spec.summary
|
17
|
-
spec.homepage =
|
18
|
+
spec.homepage = "https://dry-rb.org/gems/dry-validation"
|
18
19
|
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-validation.gemspec", "lib/**/*", "config/*.yml"]
|
19
|
-
spec.bindir =
|
20
|
+
spec.bindir = "bin"
|
20
21
|
spec.executables = []
|
21
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ["lib"]
|
22
23
|
|
23
|
-
spec.metadata[
|
24
|
-
spec.metadata[
|
25
|
-
spec.metadata[
|
26
|
-
spec.metadata[
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-validation/blob/master/CHANGELOG.md"
|
26
|
+
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-validation"
|
27
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-validation/issues"
|
27
28
|
|
28
|
-
spec.required_ruby_version = ">= 2.
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
29
30
|
|
30
31
|
# to update dependencies edit project.yml
|
31
32
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
32
33
|
spec.add_runtime_dependency "dry-container", "~> 0.7", ">= 0.7.1"
|
33
|
-
spec.add_runtime_dependency "dry-core", "~> 0.
|
34
|
-
spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
|
34
|
+
spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
|
35
35
|
spec.add_runtime_dependency "dry-initializer", "~> 3.0"
|
36
|
-
spec.add_runtime_dependency "dry-schema", "~> 1.
|
36
|
+
spec.add_runtime_dependency "dry-schema", "~> 1.9", ">= 1.9.1"
|
37
37
|
|
38
38
|
spec.add_development_dependency "bundler"
|
39
39
|
spec.add_development_dependency "rake"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "concurrent/map"
|
4
4
|
|
5
|
-
require "dry/equalizer"
|
5
|
+
require "dry/core/equalizer"
|
6
6
|
require "dry/initializer"
|
7
7
|
require "dry/schema/path"
|
8
8
|
|
@@ -68,6 +68,11 @@ module Dry
|
|
68
68
|
# @api public
|
69
69
|
option :macros, default: -> { config.macros }
|
70
70
|
|
71
|
+
# @!attribute [r] default_context
|
72
|
+
# @return [Hash] Default context for rules
|
73
|
+
# @api public
|
74
|
+
option :default_context, default: -> { EMPTY_HASH }
|
75
|
+
|
71
76
|
# @!attribute [r] schema
|
72
77
|
# @return [Dry::Schema::Params, Dry::Schema::JSON, Dry::Schema::Processor]
|
73
78
|
# @api private
|
@@ -86,12 +91,19 @@ module Dry
|
|
86
91
|
# Apply the contract to an input
|
87
92
|
#
|
88
93
|
# @param [Hash] input The input to validate
|
94
|
+
# @param [Hash] context Initial context for rules
|
89
95
|
#
|
90
96
|
# @return [Result]
|
91
97
|
#
|
92
98
|
# @api public
|
93
|
-
|
94
|
-
|
99
|
+
# rubocop: disable Metrics/AbcSize
|
100
|
+
def call(input, context = EMPTY_HASH)
|
101
|
+
context_map = Concurrent::Map.new.tap do |map|
|
102
|
+
default_context.each { |key, value| map[key] = value }
|
103
|
+
context.each { |key, value| map[key] = value }
|
104
|
+
end
|
105
|
+
|
106
|
+
Result.new(schema.(input), context_map) do |result|
|
95
107
|
rules.each do |rule|
|
96
108
|
next if rule.keys.any? { |key| error?(result, key) }
|
97
109
|
|
@@ -103,6 +115,7 @@ module Dry
|
|
103
115
|
end
|
104
116
|
end
|
105
117
|
end
|
118
|
+
# rubocop: enable Metrics/AbcSize
|
106
119
|
|
107
120
|
# Return a nice string representation
|
108
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
|
|
@@ -187,11 +187,26 @@ module Dry
|
|
187
187
|
|
188
188
|
# Check if there are any errors on the current rule
|
189
189
|
#
|
190
|
+
# @param path [Symbol, String, Array] A Path-compatible spec
|
191
|
+
#
|
192
|
+
# @return [Boolean]
|
193
|
+
#
|
194
|
+
# @api public
|
195
|
+
def rule_error?(path = nil)
|
196
|
+
if path.nil?
|
197
|
+
!key(self.path).empty?
|
198
|
+
else
|
199
|
+
result.rule_error?(path)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# Check if there are any base rule errors
|
204
|
+
#
|
190
205
|
# @return [Boolean]
|
191
206
|
#
|
192
207
|
# @api public
|
193
|
-
def
|
194
|
-
!
|
208
|
+
def base_rule_error?
|
209
|
+
!base.empty? || result.base_rule_error?
|
195
210
|
end
|
196
211
|
|
197
212
|
# @api private
|
data/lib/dry/validation/macro.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/equalizer"
|
3
|
+
require "dry/core/equalizer"
|
4
4
|
|
5
5
|
require "dry/schema/constants"
|
6
6
|
require "dry/schema/message"
|
@@ -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)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "concurrent/map"
|
4
|
-
require "dry/equalizer"
|
4
|
+
require "dry/core/equalizer"
|
5
5
|
|
6
6
|
require "dry/validation/constants"
|
7
7
|
require "dry/validation/message_set"
|
@@ -113,6 +113,20 @@ module Dry
|
|
113
113
|
schema_result.error?(key)
|
114
114
|
end
|
115
115
|
|
116
|
+
# Check if the rules includes an error for the provided key
|
117
|
+
#
|
118
|
+
# @api private
|
119
|
+
def rule_error?(key)
|
120
|
+
!schema_error?(key) && error?(key)
|
121
|
+
end
|
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
|
+
|
116
130
|
# Check if there's any error for the provided key
|
117
131
|
#
|
118
132
|
# This does not consider errors from the nested values
|
data/lib/dry/validation/rule.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/equalizer"
|
3
|
+
require "dry/core/equalizer"
|
4
4
|
require "dry/schema/path"
|
5
5
|
require "dry/validation/constants"
|
6
6
|
|
@@ -61,23 +61,31 @@ 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
|
|
68
|
+
# rubocop: disable Lint/DuplicateBranch
|
67
69
|
Schema::Path[key].reduce(hash) do |a, e|
|
68
70
|
if e.is_a?(Array)
|
69
71
|
result = e.all? { |k| key?(k, a) }
|
70
72
|
return result
|
71
73
|
elsif e.is_a?(Symbol) && a.is_a?(Array)
|
72
74
|
return false
|
75
|
+
elsif a.nil?
|
76
|
+
return false
|
77
|
+
elsif a.is_a?(String)
|
78
|
+
return false
|
73
79
|
else
|
74
80
|
return false unless a.is_a?(Array) ? (e >= 0 && e < a.size) : a.key?(e)
|
75
81
|
end
|
76
82
|
a[e]
|
77
83
|
end
|
84
|
+
# rubocop: enable Lint/DuplicateBranch
|
78
85
|
|
79
86
|
true
|
80
87
|
end
|
88
|
+
# rubocop: enable Metrics/PerceivedComplexity
|
81
89
|
|
82
90
|
# @api private
|
83
91
|
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.0
|
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: 2022-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -50,28 +50,20 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
54
|
-
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0.4'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: dry-equalizer
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
53
|
+
version: '0.5'
|
54
|
+
- - ">="
|
66
55
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0.
|
56
|
+
version: '0.5'
|
68
57
|
type: :runtime
|
69
58
|
prerelease: false
|
70
59
|
version_requirements: !ruby/object:Gem::Requirement
|
71
60
|
requirements:
|
72
61
|
- - "~>"
|
73
62
|
- !ruby/object:Gem::Version
|
74
|
-
version: '0.
|
63
|
+
version: '0.5'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.5'
|
75
67
|
- !ruby/object:Gem::Dependency
|
76
68
|
name: dry-initializer
|
77
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,14 +84,20 @@ dependencies:
|
|
92
84
|
requirements:
|
93
85
|
- - "~>"
|
94
86
|
- !ruby/object:Gem::Version
|
95
|
-
version: '1.
|
87
|
+
version: '1.9'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.9.1
|
96
91
|
type: :runtime
|
97
92
|
prerelease: false
|
98
93
|
version_requirements: !ruby/object:Gem::Requirement
|
99
94
|
requirements:
|
100
95
|
- - "~>"
|
101
96
|
- !ruby/object:Gem::Version
|
102
|
-
version: '1.
|
97
|
+
version: '1.9'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.9.1
|
103
101
|
- !ruby/object:Gem::Dependency
|
104
102
|
name: bundler
|
105
103
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,14 +190,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
190
|
requirements:
|
193
191
|
- - ">="
|
194
192
|
- !ruby/object:Gem::Version
|
195
|
-
version: 2.
|
193
|
+
version: 2.7.0
|
196
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
195
|
requirements:
|
198
196
|
- - ">="
|
199
197
|
- !ruby/object:Gem::Version
|
200
198
|
version: '0'
|
201
199
|
requirements: []
|
202
|
-
rubygems_version: 3.
|
200
|
+
rubygems_version: 3.1.6
|
203
201
|
signing_key:
|
204
202
|
specification_version: 4
|
205
203
|
summary: Validation library
|