dry-validation 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c1f46e0650eb5f6bf002b5908b561687a709b95234f94dedc113c4b3487673b
4
- data.tar.gz: 4dbc885bc2b9fca9475f6fd827462a458b99e372dae651686aad3eadee2acfbb
3
+ metadata.gz: 5c0ec5ac402da094ae496a120274c13f2a251300df9b178adb0b688968687082
4
+ data.tar.gz: b07231e7542c689d1d02cf2e8de3837592cb7867cc7772c4968034129bb65012
5
5
  SHA512:
6
- metadata.gz: 11fc47da414268f27ff60c6d0a8bea6fe1a303b94ce5400487f54a7f8f50f33c15b91039d6e6093e61755351a6a7c0dbee7efdbe0f39553f77a7a2201b1dc82d
7
- data.tar.gz: 6f69f61be289df75425a4bef4956c77c73955f564334f455abbb0e24db7a5713fb80d098d3953093703d79953fc745094805ca7ce4381df1e7b5e720efec7e1a
6
+ metadata.gz: 7d4835f01c7c8e02d63e1583f6e140efb8db33582800c2c276c94865f6841d8533b91b3fd5832944f57ad8e59f7660dcdff930dfe77e0ae17537c18f0caa14c6
7
+ data.tar.gz: e8b2cba4863b18461a8f64e6581654aecaca6525b603e40e6896199faecd5a735f8e5d1a8dbd9d6bb1ac43d562d8bb09ff3bbf77cd01d9b21d9cdef8da4f8e36
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
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
+
3
16
  ## 1.7.0 2021-09-12
4
17
 
5
18
 
data/README.md CHANGED
@@ -8,7 +8,7 @@
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/CI/badge.svg)][actions]
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
14
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-validation.svg?branch=master)][inchpages]
@@ -22,8 +22,8 @@
22
22
 
23
23
  This library officially supports the following Ruby versions:
24
24
 
25
- * MRI `>= 2.6.0`
26
- * ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
27
27
 
28
28
  ## License
29
29
 
@@ -26,14 +26,14 @@ Gem::Specification.new do |spec|
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.6.0"
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"
33
33
  spec.add_runtime_dependency "dry-container", "~> 0.7", ">= 0.7.1"
34
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.8", ">= 1.8.0"
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"
@@ -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[:'dry-validation']
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.map { |key, value| [key, _options[value]] }.to_h
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)
@@ -36,8 +36,7 @@ module Dry
36
36
  block
37
37
  .parameters
38
38
  .select { |arg,| arg.equal?(:keyreq) }
39
- .map { |_, name| [name, BLOCK_OPTIONS_MAPPINGS[name]] }
40
- .to_h
39
+ .to_h { [_2, BLOCK_OPTIONS_MAPPINGS[_2]] }
41
40
  end
42
41
  end
43
42
  end
@@ -31,7 +31,7 @@ module Dry
31
31
 
32
32
  # @api private
33
33
  def extract_block_options(options)
34
- block_options.map { |key, value| [key, options[value]] }.to_h
34
+ block_options.transform_values { options[_1] }
35
35
  end
36
36
  end
37
37
  end
@@ -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
- def message(rule, tokens: EMPTY_HASH, locale: nil, full: false, path:)
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
- Hash[
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
@@ -61,9 +61,11 @@ 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) }
@@ -79,9 +81,11 @@ module Dry
79
81
  end
80
82
  a[e]
81
83
  end
84
+ # rubocop: enable Lint/DuplicateBranch
82
85
 
83
86
  true
84
87
  end
88
+ # rubocop: enable Metrics/PerceivedComplexity
85
89
 
86
90
  # @api private
87
91
  def respond_to_missing?(meth, include_private = false)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = "1.7.0"
5
+ VERSION = "1.8.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.7.0
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: 2021-09-12 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -84,20 +84,20 @@ dependencies:
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '1.8'
87
+ version: '1.9'
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 1.8.0
90
+ version: 1.9.1
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.8'
97
+ version: '1.9'
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
- version: 1.8.0
100
+ version: 1.9.1
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: bundler
103
103
  requirement: !ruby/object:Gem::Requirement
@@ -190,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - ">="
192
192
  - !ruby/object:Gem::Version
193
- version: 2.6.0
193
+ version: 2.7.0
194
194
  required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements:
196
196
  - - ">="