dry-validation 1.5.6 → 1.6.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 +19 -6
- data/README.md +1 -1
- data/dry-validation.gemspec +1 -1
- data/lib/dry/validation/contract.rb +13 -2
- data/lib/dry/validation/evaluator.rb +8 -2
- data/lib/dry/validation/result.rb +7 -0
- data/lib/dry/validation/values.rb +4 -0
- data/lib/dry/validation/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9df6f1e542743b8e5af8438caec2b5fe705f3bba96ed9f4791eacb1efc2a627d
|
4
|
+
data.tar.gz: d027d77079c1771691f11d8f143ceb9e92834b03fb4123cdcdf48e3711dd2fba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76059d5e724680569c71ab794849379e2404b63053073fbe57394ed6031cfd0aff67b210f92b15f985feef77a986cafa7f442397e91ec3deac436f289379b126
|
7
|
+
data.tar.gz: e5e1a9a3ae536767cbba5584061e04dc01a065bccd9936b8d30482b499e4a865309400c3eff5f589a5661ba25ed1403e4a77cadc83f215b8fd6cf588dd217aa7
|
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,37 @@
|
|
1
|
-
## 1.
|
1
|
+
## 1.6.0
|
2
|
+
|
3
|
+
|
4
|
+
### Added
|
5
|
+
|
6
|
+
- You can now pass a key name or path to `rule_error?` predicate (issue #658 closed via #673) (@moofkit)
|
7
|
+
- You can now pass initial context object to `Contract#call` (issue #674 via #675) (@pyromaniac)
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
- Checking `key?` within a rule no longer crashes when value is `nil` or an empty string (issue #670 fixed via #672) (@alexxty7)
|
12
|
+
|
13
|
+
|
14
|
+
[Compare v1.5.6...master](https://github.com/dry-rb/dry-validation/compare/v1.5.6...master)
|
15
|
+
|
16
|
+
## 1.5.6 2020-09-04
|
2
17
|
|
3
|
-
2020-09-04
|
4
18
|
|
5
19
|
### Fixed
|
6
20
|
|
7
21
|
- Dependency on dry-schema was bumped to >= 1.5.1. This time for real (@solnic)
|
8
22
|
|
9
23
|
|
10
|
-
[Compare v1.5.5...
|
24
|
+
[Compare v1.5.5...v1.5.6](https://github.com/dry-rb/dry-validation/compare/v1.5.5...v1.5.6)
|
11
25
|
|
12
|
-
## 1.5.5
|
26
|
+
## 1.5.5 2020-09-03
|
13
27
|
|
14
|
-
2020-09-03
|
15
28
|
|
16
29
|
### Fixed
|
17
30
|
|
18
31
|
- Dependency on dry-schema was bumped to >= 1.5.2 (see #666 for more info) (@artofhuman)
|
19
32
|
|
20
33
|
|
21
|
-
[Compare v1.5.4...
|
34
|
+
[Compare v1.5.4...v1.5.5](https://github.com/dry-rb/dry-validation/compare/v1.5.4...v1.5.5)
|
22
35
|
|
23
36
|
## 1.5.4 2020-08-21
|
24
37
|
|
data/README.md
CHANGED
data/dry-validation.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-validation'
|
26
26
|
spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-validation/issues'
|
27
27
|
|
28
|
-
spec.required_ruby_version = ">= 2.
|
28
|
+
spec.required_ruby_version = ">= 2.5.0"
|
29
29
|
|
30
30
|
# to update dependencies edit project.yml
|
31
31
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
@@ -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,18 @@ 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
|
-
def call(input)
|
94
|
-
|
99
|
+
def call(input, context = EMPTY_HASH)
|
100
|
+
context_map = Concurrent::Map.new.tap do |map|
|
101
|
+
default_context.each { |key, value| map[key] = value }
|
102
|
+
context.each { |key, value| map[key] = value }
|
103
|
+
end
|
104
|
+
|
105
|
+
Result.new(schema.(input), context_map) do |result|
|
95
106
|
rules.each do |rule|
|
96
107
|
next if rule.keys.any? { |key| error?(result, key) }
|
97
108
|
|
@@ -187,11 +187,17 @@ 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
|
+
#
|
190
192
|
# @return [Boolean]
|
191
193
|
#
|
192
194
|
# @api public
|
193
|
-
def rule_error?
|
194
|
-
|
195
|
+
def rule_error?(path = nil)
|
196
|
+
if path.nil?
|
197
|
+
!key(self.path).empty?
|
198
|
+
else
|
199
|
+
result.rule_error?(path)
|
200
|
+
end
|
195
201
|
end
|
196
202
|
|
197
203
|
# @api private
|
@@ -113,6 +113,13 @@ 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
|
+
|
116
123
|
# Check if there's any error for the provided key
|
117
124
|
#
|
118
125
|
# This does not consider errors from the nested values
|
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.6.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: 2020-
|
11
|
+
date: 2020-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -198,14 +198,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
198
|
requirements:
|
199
199
|
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: 2.
|
201
|
+
version: 2.5.0
|
202
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
203
|
requirements:
|
204
204
|
- - ">="
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '0'
|
207
207
|
requirements: []
|
208
|
-
rubygems_version: 3.
|
208
|
+
rubygems_version: 3.1.4
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: Validation library
|