dry-validation 1.5.0 → 1.5.1

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: 5c4b57593ac3fd38a26ef3eb26a31b34503bfa75a6fc118358745aa9fb772be1
4
- data.tar.gz: 534dc4c9e0a8e83faec7077a78e4b3fd7e7fa5b55b6aa277479999332920bcb5
3
+ metadata.gz: 2deba7f8bd2d4ad011e0f4be2aa20d4f20d219d85d0eeec23d3b3e0b12c0bcf4
4
+ data.tar.gz: 12f9500062c0239d19f6bf32450db22065a9caa3062e4cb71d79a9370c3229ec
5
5
  SHA512:
6
- metadata.gz: 8268526e70a23bd00ff7825accd0b7f4ca682342a2fefab22051e756e574a8b2834d527e1c1e2cce0a7084308eb9d721dafce92b1500c793588ba9d219499e82
7
- data.tar.gz: d1ca0f28f775093521f74330dc4a09142a99c83c693aefcab1571f32343692a72c5f3669bd51baf10865fc9de93074ab3893ddfbb6412edf540bf3f2ac37b47c
6
+ metadata.gz: be6cf6d5dfce8ebec88743b7661eaf4d3cc1294cea249b87e7c02fd00b36013a033fe5feab1ccdb3e6e6020873435fbfc5bf6ee41b5f76836358973f5074843e
7
+ data.tar.gz: 77f87593b028dfa608f22835413a73fcbd7c2585e9a98c95f20a158df47fc5ca3f46a0357188f5bd1fc37140de7b57b833ae969aabe55bbdf71628f7db6f645e
@@ -1,6 +1,18 @@
1
1
  ## unreleased
2
2
 
3
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
+
10
+
11
+ [Compare v1.5.0...master](https://github.com/dry-rb/dry-validation/compare/v1.5.0...master)
12
+
13
+ ## 1.5.0 2020-03-11
14
+
15
+
4
16
  ### Added
5
17
 
6
18
  - `schema_error?` rule helper (@waiting-for-dev)
@@ -11,7 +23,7 @@
11
23
  - dry-schema dependency was bumped to `~> 1.5` (@solnic)
12
24
  - [internal] `KeyMap` patches have been removed since dry-schema now provides required functionality (@solnic)
13
25
 
14
- [Compare v1.4.2...master](https://github.com/dry-rb/dry-validation/compare/v1.4.2...master)
26
+ [Compare v1.4.2...v1.5.0](https://github.com/dry-rb/dry-validation/compare/v1.4.2...v1.5.0)
15
27
 
16
28
  ## 1.4.2 2020-01-18
17
29
 
@@ -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
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = "1.5.0"
5
+ VERSION = "1.5.1"
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.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: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby