dry-validation 1.0.0.alpha1 → 1.0.0.alpha2

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: 60a3c6ffd96f85afae4533e24216f467888d9f3bfdb3d1f01e78b292a5cceb92
4
- data.tar.gz: c6e27c162c638614e9fb876f11c8f5dde26ecc2b06edbaef62c14f6a23fd1b1d
3
+ metadata.gz: 288a3f0d9af21271cfeb794d48752ba6bfa93c8e4fa088e8faa9f6eb9a05e083
4
+ data.tar.gz: 1949525da40fb528c5eda20c610a5c017c260600613ba4fc392f23cd6a84a8d7
5
5
  SHA512:
6
- metadata.gz: 884c2d19f7de54aec614eaf90c6a11040c48f5c267482f09e6b86f8439871b7df6403762cb7885eb238d1dae0835f315abc7bbae6ff84208ea024ec33dcb93c4
7
- data.tar.gz: bf22f2906b4d9892015b58c1c0f637b10d82f5f63770a703c1b92e8d105fb3f44b7a9d822c20ffc4bacc1a63e882f13303157c13fdd6c2a65a1c42e0931195fb
6
+ metadata.gz: f4884bb2c55f0b987b0aad70bceaedc0d1bc5adc5056bd47e9606e126a9ce9bcb450f5ec7c2035b35572eb4677c4ee0c1525856fe83866b07bf559a75b97a260
7
+ data.tar.gz: f8f79772a1950752dfa03204269df85d7480c52114c4369d2e895e1edd02b6f02ee3bc03049a2c4ed0994042b104b82dd0e22fcb1c31882b7b0c741d414c8ae1
@@ -1,3 +1,19 @@
1
+ # v1.0.0.alpha2 2019-03-05
2
+
3
+ First round of bug fixes. Thanks for testing <3!
4
+
5
+ ### Fixed
6
+
7
+ * Errors with nested messages are correctly built (flash-gordon)
8
+ * Messages for nested keys are correctly resolved (solnic)
9
+ * A message for a nested key is resolved when it's defined under `errors.rule.%{key}` too, but a message under nested key will override it (solnic)
10
+
11
+ ### Changed
12
+
13
+ * When a message template is not found a more meaningful error is raised that includes both rule identifier and key path (solnic)
14
+
15
+ [Compare v1.0.0.alpha1...v1.0.0.alpha2](https://github.com/dry-rb/dry-validation/compare/v1.0.0.alpha1...v1.0.0.alpha2)
16
+
1
17
  # v1.0.0.alpha1 2019-03-04
2
18
 
3
19
  Complete rewrite on top of `dry-schema`.
@@ -26,7 +42,7 @@ Complete rewrite on top of `dry-schema`.
26
42
 
27
43
  ### Changed
28
44
 
29
- * [internal] dyr-logic was pinned to `~> 0.4.2` (flash-gordon)
45
+ * [internal] dry-logic was pinned to `~> 0.4.2` (flash-gordon)
30
46
 
31
47
  [Compare v0.12.2...v0.12.3](https://github.com/dry-rb/dry-validation/compare/v0.12.2...v0.12.3)
32
48
 
@@ -6,6 +6,8 @@ module Dry
6
6
  module Validation
7
7
  include Dry::Core::Constants
8
8
 
9
+ DOT = '.'
10
+
9
11
  MissingMessageError = Class.new(StandardError)
10
12
  DuplicateSchemaError = Class.new(StandardError)
11
13
  end
@@ -119,13 +119,19 @@ module Dry
119
119
  #
120
120
  # @api private
121
121
  def message(key, tokens: EMPTY_HASH, **opts)
122
- template = messages[key, opts.merge(tokens)]
122
+ msg_opts = opts.merge(tokens)
123
+ rule_path = Array(opts.fetch(:rule)).flatten
123
124
 
124
- if template
125
- template.(template.data(tokens))
126
- else
127
- raise MissingMessageError, "Message template for #{key.inspect} was not found"
125
+ template = messages[key, msg_opts.merge(rule: rule_path.join(DOT))]
126
+ template ||= messages[key, msg_opts.merge(rule: rule_path.last)]
127
+
128
+ unless template
129
+ raise MissingMessageError, <<~STR
130
+ Message template for #{key.inspect} under #{rule_path.join(DOT).inspect} was not found
131
+ STR
128
132
  end
133
+
134
+ template.(template.data(tokens))
129
135
  end
130
136
  end
131
137
  end
@@ -74,7 +74,7 @@ module Dry
74
74
  #
75
75
  # @api private
76
76
  def add_error(key, message)
77
- (errors[key] ||= EMPTY_ARRAY.dup) << message
77
+ add_to(errors, key, message)
78
78
  self
79
79
  end
80
80
 
@@ -86,7 +86,13 @@ module Dry
86
86
  #
87
87
  # @api public
88
88
  def [](key)
89
- values.key?(key) && values[key] || storage.key?(key) && storage[key]
89
+ if values.key?(key)
90
+ values[key]
91
+ elsif storage.key?(key)
92
+ storage[key]
93
+ else
94
+ nil
95
+ end
90
96
  end
91
97
 
92
98
  # Store value under specified key
@@ -142,6 +148,17 @@ module Dry
142
148
  def storage
143
149
  @storage ||= EMPTY_HASH.dup
144
150
  end
151
+
152
+ # @api private
153
+ def add_to(hash, path, value)
154
+ if path.is_a?(Hash)
155
+ key = path.keys[0]
156
+ messages = (hash[key] ||= EMPTY_HASH.dup)
157
+ add_to(messages, path[key], value)
158
+ else
159
+ (hash[path] ||= EMPTY_ARRAY.dup) << value
160
+ end
161
+ end
145
162
  end
146
163
  end
147
164
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = '1.0.0.alpha1'.freeze
5
+ VERSION = '1.0.0.alpha2'
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.0.0.alpha1
4
+ version: 1.0.0.alpha2
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-03-04 00:00:00.000000000 Z
11
+ date: 2019-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby