dry-validation 1.5.0 → 1.5.2

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: 5c4b57593ac3fd38a26ef3eb26a31b34503bfa75a6fc118358745aa9fb772be1
4
- data.tar.gz: 534dc4c9e0a8e83faec7077a78e4b3fd7e7fa5b55b6aa277479999332920bcb5
3
+ metadata.gz: 83395b144bcdc666d13ac3cb100e2a7488ba9caa638067f03beee031964da26a
4
+ data.tar.gz: fa5f1480a6bff63238c76ffc6ee8c574ccc113048843d5f79c9fdc216b899d23
5
5
  SHA512:
6
- metadata.gz: 8268526e70a23bd00ff7825accd0b7f4ca682342a2fefab22051e756e574a8b2834d527e1c1e2cce0a7084308eb9d721dafce92b1500c793588ba9d219499e82
7
- data.tar.gz: d1ca0f28f775093521f74330dc4a09142a99c83c693aefcab1571f32343692a72c5f3669bd51baf10865fc9de93074ab3893ddfbb6412edf540bf3f2ac37b47c
6
+ metadata.gz: 7d14bcf252cbf7cd6a2d58f936d65da3e71343388b87924f51f56cd7812fecff33bab17f4193cf354cc76fd7d3bbbd2081e847b0c8b54b466c1781599aeba25b
7
+ data.tar.gz: 11d241432260233c0b7f8fe03b69e1a2cd44e0e7fd241a90ba5f3eb65eff4f21e7c8c88e3fa5c903dc65dbbd78de537a03368ba47cf714a295c7da8784286af8
@@ -1,4 +1,30 @@
1
- ## unreleased
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...master](https://github.com/dry-rb/dry-validation/compare/v1.4.2...master)
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
@@ -25,7 +25,7 @@ module Dry
25
25
  # end
26
26
  #
27
27
  # @param [Symbol] name The name of the macro
28
- # @param [Array] *args Optional default arguments for the macro
28
+ # @param [Array] args Optional default positional arguments for the macro
29
29
  #
30
30
  # @return [self]
31
31
  #
@@ -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] key
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = "1.5.0"
5
+ VERSION = "1.5.2"
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.0
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-03-11 00:00:00.000000000 Z
11
+ date: 2020-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby