dry-validation 1.1.0 → 1.1.1
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 +8 -0
- data/lib/dry/validation.rb +3 -0
- data/lib/dry/validation/constants.rb +6 -0
- data/lib/dry/validation/contract.rb +5 -3
- data/lib/dry/validation/messages/resolver.rb +3 -0
- data/lib/dry/validation/result.rb +2 -2
- data/lib/dry/validation/rule.rb +6 -3
- data/lib/dry/validation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3821e92d2dced61bb892e20a5e5d69b596128fcdbd05596e41fff8716767b08c
|
4
|
+
data.tar.gz: f797d5e46604e777966cb3d9a7a4032265227684164224a8ff109fc8ba51d1c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7504498b77c794b9fe37e0384fba50a8fb6c99e3fecd3423e66fe018006288b3ba1a5a7a2232fb53dede256ba0a13630313748a0214b4a0d9865fc22c0b9edae
|
7
|
+
data.tar.gz: 654233d365e7844985f465e16335a234a2d5c2c240b97a485d286a52e6229e3ee80d8719e76d3ec95fe393d75f480617452b7813cb36b4b033021f9b98958461
|
data/CHANGELOG.md
CHANGED
data/lib/dry/validation.rb
CHANGED
@@ -41,9 +41,12 @@ module Dry
|
|
41
41
|
# @return [Contract]
|
42
42
|
#
|
43
43
|
# @api public
|
44
|
+
#
|
45
|
+
# rubocop:disable Naming/MethodName
|
44
46
|
def self.Contract(options = EMPTY_HASH, &block)
|
45
47
|
Contract.build(options, &block)
|
46
48
|
end
|
49
|
+
# rubocop:enable Naming/MethodName
|
47
50
|
|
48
51
|
# This is needed by Macros::Registrar
|
49
52
|
#
|
@@ -11,6 +11,12 @@ module Dry
|
|
11
11
|
# Root path is used for base errors in hash representation of error messages
|
12
12
|
ROOT_PATH = [nil].freeze
|
13
13
|
|
14
|
+
# Path to the default errors locale file
|
15
|
+
DEFAULT_ERRORS_NAMESPACE = 'dry_validation'
|
16
|
+
|
17
|
+
# Path to the default errors locale file
|
18
|
+
DEFAULT_ERRORS_PATH = Pathname(__FILE__).join('../../../../config/errors.yml').realpath.freeze
|
19
|
+
|
14
20
|
# Mapping for block kwarg options used by block_options
|
15
21
|
#
|
16
22
|
# @see Rule#block_options
|
@@ -54,8 +54,8 @@ module Dry
|
|
54
54
|
extend Dry::Initializer
|
55
55
|
extend ClassInterface
|
56
56
|
|
57
|
-
config.messages.top_namespace =
|
58
|
-
config.messages.load_paths <<
|
57
|
+
config.messages.top_namespace = DEFAULT_ERRORS_NAMESPACE
|
58
|
+
config.messages.load_paths << DEFAULT_ERRORS_PATH
|
59
59
|
|
60
60
|
# @!attribute [r] config
|
61
61
|
# @return [Config] Contract's configuration object
|
@@ -118,7 +118,9 @@ module Dry
|
|
118
118
|
# @api private
|
119
119
|
def error?(result, key)
|
120
120
|
path = Schema::Path[key]
|
121
|
-
|
121
|
+
|
122
|
+
result.error?(path) ||
|
123
|
+
path.map.with_index { |_k, i| result.error?(path.keys[0..i - 2]) }.any?
|
122
124
|
end
|
123
125
|
|
124
126
|
# Get a registered macro
|
@@ -49,6 +49,8 @@ module Dry
|
|
49
49
|
# @return [String]
|
50
50
|
#
|
51
51
|
# @api public
|
52
|
+
#
|
53
|
+
# rubocop:disable Metrics/AbcSize
|
52
54
|
def message(rule, tokens: EMPTY_HASH, locale: nil, full: false, path:)
|
53
55
|
keys = path.to_a.compact
|
54
56
|
msg_opts = tokens.merge(path: keys, locale: locale || messages.default_locale)
|
@@ -70,6 +72,7 @@ module Dry
|
|
70
72
|
|
71
73
|
[full ? "#{messages.rule(keys.last, msg_opts)} #{text}" : text, meta]
|
72
74
|
end
|
75
|
+
# rubocop:enable Metrics/AbcSize
|
73
76
|
end
|
74
77
|
end
|
75
78
|
end
|
@@ -148,9 +148,9 @@ module Dry
|
|
148
148
|
# @api public
|
149
149
|
def inspect
|
150
150
|
if context.empty?
|
151
|
-
"#<#{self.class}#{to_h
|
151
|
+
"#<#{self.class}#{to_h} errors=#{errors.to_h}>"
|
152
152
|
else
|
153
|
-
"#<#{self.class}#{to_h
|
153
|
+
"#<#{self.class}#{to_h} errors=#{errors.to_h} context=#{context.each.to_h}>"
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
data/lib/dry/validation/rule.rb
CHANGED
@@ -69,18 +69,21 @@ module Dry
|
|
69
69
|
# key.failure("must be greater than 0") if value < 0
|
70
70
|
# end
|
71
71
|
# rule(:nums).each(min: 3)
|
72
|
+
# rule(address: :city) do
|
73
|
+
# key.failure("oops") if value != 'Munich'
|
74
|
+
# end
|
72
75
|
#
|
73
76
|
# @return [Rule]
|
74
77
|
#
|
75
78
|
# @api public
|
76
79
|
def each(*macros, &block)
|
77
|
-
root = keys
|
80
|
+
root = keys[0]
|
78
81
|
macros = parse_macros(*macros)
|
79
82
|
@keys = []
|
80
83
|
|
81
84
|
@block = proc do
|
82
|
-
values[root].each_with_index do |_, idx|
|
83
|
-
path = [*root, idx]
|
85
|
+
(values[root] || []).each_with_index do |_, idx|
|
86
|
+
path = [*Schema::Path[root].to_a, idx]
|
84
87
|
|
85
88
|
next if result.error?(path)
|
86
89
|
|
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|