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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baed168e736076bb6f402d21c43f79b7f14014d2c86c2cb4c5ff0d286ed340b1
4
- data.tar.gz: 648d5963b3d6a25c71e9bac28ff3476318599f50c989d2299486f826109b4015
3
+ metadata.gz: 9df6f1e542743b8e5af8438caec2b5fe705f3bba96ed9f4791eacb1efc2a627d
4
+ data.tar.gz: d027d77079c1771691f11d8f143ceb9e92834b03fb4123cdcdf48e3711dd2fba
5
5
  SHA512:
6
- metadata.gz: 5de2142ce8dc474eded404e9f13904ab824dd044ad6be1e3054773b0846ee5987c3008244dacab8595cce94cbb500fb30e3f1a8d435bbed8e400e64065c1c80a
7
- data.tar.gz: bfbf80ec801ad412437f3f7a95f205d4f85004ba1ff93af61db4c21deb01063bb39b6e389eac761728721de55e14716e16e7eb07d9f53771f4ea18d7564a00b7
6
+ metadata.gz: 76059d5e724680569c71ab794849379e2404b63053073fbe57394ed6031cfd0aff67b210f92b15f985feef77a986cafa7f442397e91ec3deac436f289379b126
7
+ data.tar.gz: e5e1a9a3ae536767cbba5584061e04dc01a065bccd9936b8d30482b499e4a865309400c3eff5f589a5661ba25ed1403e4a77cadc83f215b8fd6cf588dd217aa7
@@ -1,24 +1,37 @@
1
- ## 1.5.5
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...master](https://github.com/dry-rb/dry-validation/compare/v1.5.5...master)
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...master](https://github.com/dry-rb/dry-validation/compare/v1.5.4...master)
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
@@ -21,7 +21,7 @@
21
21
 
22
22
  This library officially supports the following Ruby versions:
23
23
 
24
- * MRI >= `2.4`
24
+ * MRI >= `2.5`
25
25
  * jruby >= `9.2`
26
26
 
27
27
  ## License
@@ -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.4.0"
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
- Result.new(schema.(input), Concurrent::Map.new) do |result|
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
- !key(path).empty?
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
@@ -70,6 +70,10 @@ module Dry
70
70
  return result
71
71
  elsif e.is_a?(Symbol) && a.is_a?(Array)
72
72
  return false
73
+ elsif a.nil?
74
+ return false
75
+ elsif a.is_a?(String)
76
+ return false
73
77
  else
74
78
  return false unless a.is_a?(Array) ? (e >= 0 && e < a.size) : a.key?(e)
75
79
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = "1.5.6"
5
+ VERSION = "1.6.0"
6
6
  end
7
7
  end
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.5.6
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-09-04 00:00:00.000000000 Z
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.4.0
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.0.3
208
+ rubygems_version: 3.1.4
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: Validation library