dry-validation 1.1.0 → 1.1.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: 4985e6191e9e249b510fceea630ed463f11c5ff07830e6f3f867e913b29860ac
4
- data.tar.gz: 99cb37716fb12f4a09bb94a4048935e6ac8db658df4d5a4318be321c5aef90ff
3
+ metadata.gz: 3821e92d2dced61bb892e20a5e5d69b596128fcdbd05596e41fff8716767b08c
4
+ data.tar.gz: f797d5e46604e777966cb3d9a7a4032265227684164224a8ff109fc8ba51d1c1
5
5
  SHA512:
6
- metadata.gz: 2d25a5df6a56b6a8ed32f19ed3991297f2d878d24ba5349fd8c8d0ec50a3503842c8b591d7b176ddf9303b78a847002e638faeb29691329db3b2f41d2379116b
7
- data.tar.gz: a21649e2476c688f9a4275e43819640823c6e6a2caf18e4b8d03c0df97c946d5edbb517c6482918bf3b3b9bc21079e667c06986c2adc81acdeb0561b1bc264aa
6
+ metadata.gz: 7504498b77c794b9fe37e0384fba50a8fb6c99e3fecd3423e66fe018006288b3ba1a5a7a2232fb53dede256ba0a13630313748a0214b4a0d9865fc22c0b9edae
7
+ data.tar.gz: 654233d365e7844985f465e16335a234a2d5c2c240b97a485d286a52e6229e3ee80d8719e76d3ec95fe393d75f480617452b7813cb36b4b033021f9b98958461
@@ -1,3 +1,11 @@
1
+ # v1.1.1 2019-06-24
2
+
3
+ ### Fixed
4
+
5
+ * `Rule#each` works with array values from nested hashes (@mustardnoise)
6
+
7
+ [Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-validation/compare/v1.1.0...v1.1.1)
8
+
1
9
  # v1.1.0 2019-06-14
2
10
 
3
11
  ### Added
@@ -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 = 'dry_validation'
58
- config.messages.load_paths << Pathname(__FILE__).join('../../../../config/errors.yml').realpath
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
- result.error?(path) || path.map.with_index { |_k, i| result.error?(path.keys[0..i - 2]) }.any?
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.inspect} errors=#{errors.to_h.inspect}>"
151
+ "#<#{self.class}#{to_h} errors=#{errors.to_h}>"
152
152
  else
153
- "#<#{self.class}#{to_h.inspect} errors=#{errors.to_h.inspect} context=#{context.each.to_h.inspect}>"
153
+ "#<#{self.class}#{to_h} errors=#{errors.to_h} context=#{context.each.to_h}>"
154
154
  end
155
155
  end
156
156
 
@@ -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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.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.1.0
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-14 00:00:00.000000000 Z
11
+ date: 2019-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby