dry-validation 1.5.0 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -2
- data/lib/dry/validation/evaluator.rb +2 -2
- data/lib/dry/validation/extensions/hints.rb +1 -3
- data/lib/dry/validation/macros.rb +1 -1
- data/lib/dry/validation/message_set.rb +1 -1
- data/lib/dry/validation/messages/resolver.rb +13 -1
- data/lib/dry/validation/values.rb +6 -1
- 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: 83395b144bcdc666d13ac3cb100e2a7488ba9caa638067f03beee031964da26a
|
4
|
+
data.tar.gz: fa5f1480a6bff63238c76ffc6ee8c574ccc113048843d5f79c9fdc216b899d23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d14bcf252cbf7cd6a2d58f936d65da3e71343388b87924f51f56cd7812fecff33bab17f4193cf354cc76fd7d3bbbd2081e847b0c8b54b466c1781599aeba25b
|
7
|
+
data.tar.gz: 11d241432260233c0b7f8fe03b69e1a2cd44e0e7fd241a90ba5f3eb65eff4f21e7c8c88e3fa5c903dc65dbbd78de537a03368ba47cf714a295c7da8784286af8
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,30 @@
|
|
1
|
-
##
|
1
|
+
## 1.5.1 2020-06-18
|
2
|
+
|
3
|
+
|
4
|
+
### Fixed
|
5
|
+
|
6
|
+
- dry-monads no longer required for the `:hints` extension (@schokomarie)
|
7
|
+
- Using `full: true` option works as expected with custom rule messages (issue #618 fixed via #651) (@sirfilip)
|
8
|
+
- Using `locale: ...` option works as expected with hints (issue #589 fixed via #652) (@sirfilip)
|
9
|
+
- `key?` predicate in rules no longer crashes when the rule path points to a non-existent array value (issue #653 fixed via #654) (@solnic)
|
10
|
+
|
11
|
+
|
12
|
+
[Compare v1.5.1...v1.5.1](https://github.com/dry-rb/dry-validation/compare/v1.5.1...v1.5.1)
|
13
|
+
|
14
|
+
## 1.5.1 2020-06-18
|
15
|
+
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- dry-monads no longer required for the `:hints` extension (@schokomarie)
|
20
|
+
- Using `full: true` option works as expected with custom rule messages (issue #618 fixed via #651) (@sirfilip)
|
21
|
+
- Using `locale: ...` option works as expected with hints (issue #589 fixed via #652) (@sirfilip)
|
22
|
+
- `key?` predicate in rules no longer crashes when the rule path points to a non-existent array value (issue #653 fixed via #654) (@solnic)
|
23
|
+
|
24
|
+
|
25
|
+
[Compare v1.5.0...v1.5.1](https://github.com/dry-rb/dry-validation/compare/v1.5.0...v1.5.1)
|
26
|
+
|
27
|
+
## 1.5.0 2020-03-11
|
2
28
|
|
3
29
|
|
4
30
|
### Added
|
@@ -11,7 +37,7 @@
|
|
11
37
|
- dry-schema dependency was bumped to `~> 1.5` (@solnic)
|
12
38
|
- [internal] `KeyMap` patches have been removed since dry-schema now provides required functionality (@solnic)
|
13
39
|
|
14
|
-
[Compare v1.4.2...
|
40
|
+
[Compare v1.4.2...v1.5.0](https://github.com/dry-rb/dry-validation/compare/v1.4.2...v1.5.0)
|
15
41
|
|
16
42
|
## 1.4.2 2020-01-18
|
17
43
|
|
@@ -146,7 +146,7 @@ module Dry
|
|
146
146
|
#
|
147
147
|
# @return [Object]
|
148
148
|
#
|
149
|
-
# @public
|
149
|
+
# @api public
|
150
150
|
def value
|
151
151
|
values[key_name]
|
152
152
|
end
|
@@ -169,7 +169,7 @@ module Dry
|
|
169
169
|
|
170
170
|
# Check if there are any errors on the schema under the provided path
|
171
171
|
#
|
172
|
-
# @param [Symbol, String, Array] A Path-compatible spec
|
172
|
+
# @param path [Symbol, String, Array] A Path-compatible spec
|
173
173
|
#
|
174
174
|
# @return [Boolean]
|
175
175
|
#
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/monads/result"
|
4
|
-
|
5
3
|
module Dry
|
6
4
|
module Validation
|
7
5
|
# Hints extension
|
@@ -46,7 +44,7 @@ module Dry
|
|
46
44
|
#
|
47
45
|
# @api public
|
48
46
|
def messages(new_options = EMPTY_HASH)
|
49
|
-
errors.with(hints.to_a, options.merge(**new_options))
|
47
|
+
errors.with(hints(new_options).to_a, options.merge(**new_options))
|
50
48
|
end
|
51
49
|
|
52
50
|
# Return hint messages
|
@@ -85,7 +85,7 @@ module Dry
|
|
85
85
|
# @api private
|
86
86
|
def freeze
|
87
87
|
source_messages.select { |err| err.respond_to?(:evaluate) }.each do |err|
|
88
|
-
idx = source_messages.index(err)
|
88
|
+
idx = messages.index(err) || source_messages.index(err)
|
89
89
|
msg = err.evaluate(locale: locale, full: options[:full])
|
90
90
|
messages[idx] = msg
|
91
91
|
end
|
@@ -33,7 +33,7 @@ module Dry
|
|
33
33
|
when Symbol
|
34
34
|
Message[->(**opts) { message(message, path: path, tokens: tokens, **opts) }, path, meta]
|
35
35
|
when String
|
36
|
-
Message[message, path, meta]
|
36
|
+
Message[->(**opts) { [message_text(message, path, **opts), meta] }, path, meta]
|
37
37
|
when Hash
|
38
38
|
meta = message.dup
|
39
39
|
text = meta.delete(:text) { |key|
|
@@ -51,6 +51,18 @@ module Dry
|
|
51
51
|
end
|
52
52
|
alias_method :[], :call
|
53
53
|
|
54
|
+
# Resolve a message
|
55
|
+
#
|
56
|
+
# @return String
|
57
|
+
#
|
58
|
+
# @api public
|
59
|
+
def message_text(message, path, locale: nil, full: false, **opts)
|
60
|
+
keys = path.to_a.compact
|
61
|
+
msg_opts = EMPTY_HASH.merge(path: keys, locale: locale || messages.default_locale)
|
62
|
+
|
63
|
+
full ? "#{messages.rule(keys.last, msg_opts) || keys.last} #{message}" : message
|
64
|
+
end
|
65
|
+
|
54
66
|
# Resolve a message
|
55
67
|
#
|
56
68
|
# @return [String]
|
@@ -35,7 +35,10 @@ module Dry
|
|
35
35
|
# key.failure('must be > 18') if values[:age] <= 18
|
36
36
|
# end
|
37
37
|
#
|
38
|
-
# @param [Symbol]
|
38
|
+
# @param args [Symbol, String, Hash, Array<Symbol>] If given as a single
|
39
|
+
# Symbol, String, Array or Hash, build a key array using
|
40
|
+
# {Dry::Schema::Path} digging for data. If given as positional
|
41
|
+
# arguments, use these with Hash#dig on the data directly.
|
39
42
|
#
|
40
43
|
# @return [Object]
|
41
44
|
#
|
@@ -65,6 +68,8 @@ module Dry
|
|
65
68
|
if e.is_a?(Array)
|
66
69
|
result = e.all? { |k| key?(k, a) }
|
67
70
|
return result
|
71
|
+
elsif e.is_a?(Symbol) && a.is_a?(Array)
|
72
|
+
return false
|
68
73
|
else
|
69
74
|
return false unless a.is_a?(Array) ? (e >= 0 && e < a.size) : a.key?(e)
|
70
75
|
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.
|
4
|
+
version: 1.5.2
|
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-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|