dry-schema 1.5.0 → 1.5.5

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: 45a3441f7099ddd2ea6c0af6345f1fdcff20cf0629953dfc1eedcce5f8f54995
4
- data.tar.gz: 841584478740cfc72a653e50445b9e3a16c01a6ce49b2c8c8375da76811ca50d
3
+ metadata.gz: 442f6c2c04925f14ec6f0230394ad8e009518e9a2d7c1db22ddf68416324d530
4
+ data.tar.gz: 8f210323df91ba5ebf8a947b5888907b6f6f7cac504f93fbec80af8678dbdeb1
5
5
  SHA512:
6
- metadata.gz: 368b80c79f2598dd4cf215c8223dbd704b75909857acf9fa51e60abed19ba3bdc2904ce5d7227ef7259b45593017131ce6ab5434ee3d713fe6b97eed643eecd8
7
- data.tar.gz: 4f5ac8469feb749ed6ca95c022f99b822204d1b1cdde05969795571cabd43cd573111c86cfb4322413a22b5e99958156ba061a598c381989510ecf700fbfc7f0
6
+ metadata.gz: 87c2dcc7e169f2ff4c474038a0821a77e9f71420d40d2a4fe59f1d0ab722bcbbc3b9a60dcb33107d34d77cd303a82c33ebb3d084c350a49fc13e7b4cd73666f8
7
+ data.tar.gz: 59442e66361d9a1daf9de31480681bf0414875f22b9cdd440224db7b1a5fde818bdc479e2296cea558b00e9b698df56645aa65a55da59bb2bde2d67b4b979120
@@ -1,3 +1,64 @@
1
+ ## 1.5.5 2020-10-08
2
+
3
+
4
+ ### Fixed
5
+
6
+ - Key validation works with messages that have meta-data (issue #310 fixed via #313) (@tadeusz-niemiec)
7
+ - Using an external schema along with a key specified as a `:hash` works as expected (issue #296 fixed via #315) (@tadeusz-niemiec + @solnic)
8
+ - `Result#error?(path)` works correctly when the path points to an array item (issue #317 fixed via #318) (@solnic)
9
+
10
+
11
+ [Compare v1.5.4...v1.5.5](https://github.com/dry-rb/dry-schema/compare/v1.5.4...v1.5.5)
12
+
13
+ ## 1.5.4
14
+
15
+ 2020-09-03
16
+
17
+ ### Fixed
18
+
19
+ - Key validation works correctly with a non-nested maybe hashes (issue #311 fixed via #312) (@svobom57)
20
+
21
+
22
+ [Compare v1.5.3...master](https://github.com/dry-rb/dry-schema/compare/v1.5.3...master)
23
+
24
+ ## 1.5.3 2020-08-21
25
+
26
+
27
+ ### Fixed
28
+
29
+ - Key validator works correctly with an array with maybe hash as its member (issue #308 fixed via #309) (@tadeusz-niemiec)
30
+
31
+ ### Changed
32
+
33
+ - [info extension] small performance improvement in the set visitor (see #305 for more details) (@esparta)
34
+
35
+ [Compare v1.5.2...v1.5.3](https://github.com/dry-rb/dry-schema/compare/v1.5.2...v1.5.3)
36
+
37
+ ## 1.5.2 2020-06-26
38
+
39
+
40
+ ### Fixed
41
+
42
+ - `Result#{success?,failure?}` work as expected when there are only key validation failures (issue #297 fixed via #298) (@adamransom)
43
+
44
+ ### Changed
45
+
46
+ - Using `full` option no longer adds a space between the name of a key and the message in case of languages that have no spaces between words (ie Japanese) (issue #161 closed via #292 by @tadeusz-niemiec)
47
+
48
+ [Compare v1.5.1...v1.5.2](https://github.com/dry-rb/dry-schema/compare/v1.5.1...v1.5.2)
49
+
50
+ ## 1.5.1 2020-05-21
51
+
52
+
53
+ ### Fixed
54
+
55
+ - Negated predicates support the logic operator API now (fixed via #276 by @solnic)
56
+ - Fixed circular require warning (issue #279 closed via #282 by @landongrindheim)
57
+ - Validating keys against an array with non-hash members no longer crashes (issue #283 fixed via #284 by @beechnut and issue #289 fixed via #288 by @tadeusz-niemiec)
58
+
59
+
60
+ [Compare v1.5.0...v1.5.1](https://github.com/dry-rb/dry-schema/compare/v1.5.0...v1.5.1)
61
+
1
62
  ## 1.5.0 2020-03-11
2
63
 
3
64
 
@@ -30,7 +30,7 @@ module Dry
30
30
  # used as nested schemas
31
31
  #
32
32
  # @param [Array] node
33
- # @param [Hash] opts
33
+ # @param [Hash] _opts Unused
34
34
  #
35
35
  # @return [NamespacedRule]
36
36
  #
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "dry/initializer"
4
4
 
5
- require "dry/schema"
6
5
  require "dry/schema/constants"
7
6
  require "dry/schema/path"
8
7
  require "dry/schema/config"
@@ -50,7 +50,7 @@ module Dry
50
50
  def visit_set(node, opts = EMPTY_HASH)
51
51
  target = (key = opts[:key]) ? self.class.new : self
52
52
 
53
- node.map { |child| target.visit(child, opts) }
53
+ node.each { |child| target.visit(child, opts) }
54
54
 
55
55
  return unless key
56
56
 
@@ -28,11 +28,11 @@ module Dry
28
28
  if path[INDEX_REGEX]
29
29
  key = path.gsub(INDEX_REGEX, BRACKETS)
30
30
 
31
- unless key_paths.include?(key)
31
+ if key_paths.none? { |key_path| key_path.include?(key) }
32
32
  arr = path.gsub(INDEX_REGEX) { |m| ".#{m[1]}" }
33
33
  arr.split(DOT).map { |s| DIGIT_REGEX.match?(s) ? s.to_i : s.to_sym }
34
34
  end
35
- elsif !key_paths.include?(path)
35
+ elsif key_paths.none? { |key_path| key_path.include?(path) }
36
36
  path
37
37
  end
38
38
 
@@ -53,7 +53,8 @@ module Dry
53
53
  when Hash
54
54
  [key].product(key_paths(hash[key])).map { |keys| keys.join(DOT) }
55
55
  when Array
56
- value.flat_map.with_index { |el, idx|
56
+ hashes_or_arrays = value.select { |e| e.is_a?(Array) || e.is_a?(Hash) }
57
+ hashes_or_arrays.flat_map.with_index { |el, idx|
57
58
  key_paths(el).map { |path| ["#{key}[#{idx}]", *path].join(DOT) }
58
59
  }
59
60
  else
@@ -28,10 +28,14 @@ module Dry
28
28
 
29
29
  import_steps(schema)
30
30
 
31
- type(updated_type) unless custom_type? && !current_type.respond_to?(:of)
31
+ if !custom_type? || array_type?(current_type) || hash_type?(current_type)
32
+ type(updated_type)
33
+ elsif maybe_type?(current_type)
34
+ type(updated_type.optional)
35
+ end
32
36
  end
33
37
 
34
- trace_opts = opts.reject { |key, _| key == :type_spec || key == :type_rule }
38
+ trace_opts = opts.reject { |key, _| %i[type_spec type_rule].include?(key) }
35
39
 
36
40
  if (type_rule = opts[:type_rule])
37
41
  trace.append(type_rule).evaluate(*predicates, **trace_opts)
@@ -62,10 +66,16 @@ module Dry
62
66
  primitive_inferrer[type].eql?([::Array])
63
67
  end
64
68
 
69
+ # @api private
65
70
  def hash_type?(type)
66
71
  primitive_inferrer[type].eql?([::Hash])
67
72
  end
68
73
 
74
+ # @api private
75
+ def maybe_type?(type)
76
+ type.meta[:maybe].equal?(true)
77
+ end
78
+
69
79
  # @api private
70
80
  def build_array_type(array_type, member)
71
81
  if array_type.respond_to?(:of)
@@ -29,6 +29,14 @@ module Dry
29
29
 
30
30
  EMPTY_OPTS = VisitorOpts.new
31
31
  EMPTY_MESSAGE_SET = MessageSet.new(EMPTY_ARRAY).freeze
32
+ FULL_MESSAGE_WHITESPACE = Hash.new(' ').merge(
33
+ ja: '',
34
+ zh: '',
35
+ bn: '',
36
+ th: '',
37
+ lo: '',
38
+ my: '',
39
+ )
32
40
 
33
41
  param :messages
34
42
 
@@ -108,6 +116,7 @@ module Dry
108
116
 
109
117
  Message.new(
110
118
  path: path,
119
+ meta: msg[:meta] || EMPTY_HASH,
111
120
  text: msg[:text],
112
121
  predicate: nil,
113
122
  input: input
@@ -203,12 +212,12 @@ module Dry
203
212
  return text if !text || !full
204
213
 
205
214
  rule = options[:path]
206
- "#{messages.rule(rule, options) || rule} #{text}"
215
+ [messages.rule(rule, options) || rule, text].join(FULL_MESSAGE_WHITESPACE[template.options[:locale]])
207
216
  end
208
217
 
209
218
  # @api private
210
219
  def message_tokens(args)
211
- args.each_with_object({}) do |arg, hash|
220
+ tokens = args.each_with_object({}) do |arg, hash|
212
221
  case arg[1]
213
222
  when Array
214
223
  hash[arg[0]] = arg[1].join(LIST_SEPARATOR)
@@ -219,6 +228,14 @@ module Dry
219
228
  hash[arg[0]] = arg[1]
220
229
  end
221
230
  end
231
+ args.any? { |e| e.first == :size } ? append_mapped_size_tokens(tokens) : tokens
232
+ end
233
+
234
+ # @api private
235
+ def append_mapped_size_tokens(tokens)
236
+ # this is a temporary fix for the inconsistency in the "size" errors arguments
237
+ mapped_hash = tokens.each_with_object({}) { |(k, v), h| h[k.to_s.gsub("size", "num").to_sym] = v }
238
+ tokens.merge(mapped_hash)
222
239
  end
223
240
  end
224
241
  end
@@ -90,14 +90,29 @@ module Dry
90
90
  keys.index(key)
91
91
  end
92
92
 
93
+ def without_index
94
+ self.class.new([*to_a[0..-2]])
95
+ end
96
+
93
97
  # @api private
98
+ #
99
+ # rubocop:disable Metrics/PerceivedComplexity
94
100
  def include?(other)
95
101
  return false unless same_root?(other)
96
102
  return last.equal?(other.last) if index? && other.index?
97
- return self.class.new([*to_a[0..-2]]).include?(other) if index?
103
+ return without_index.include?(other) if index?
104
+
105
+ if !index? && other.index?
106
+ path = key_matches(other, :select)
107
+
108
+ return false unless path.size > 1
109
+
110
+ self.class.new(path).include?(other)
111
+ end
98
112
 
99
113
  self >= other && !other.key_matches(self).include?(nil)
100
114
  end
115
+ # rubocop:enable Metrics/PerceivedComplexity
101
116
 
102
117
  # @api private
103
118
  def <=>(other)
@@ -13,6 +13,8 @@ module Dry
13
13
  #
14
14
  # @api private
15
15
  class Negation
16
+ include Dry::Logic::Operators
17
+
16
18
  # @api private
17
19
  attr_reader :predicate
18
20
 
@@ -43,7 +43,7 @@ module Dry
43
43
 
44
44
  # Return a new result scoped to a specific path
45
45
  #
46
- # @param [Symbol, Array, Path]
46
+ # @param path [Symbol, Array, Path]
47
47
  #
48
48
  # @return [Result]
49
49
  #
@@ -121,7 +121,7 @@ module Dry
121
121
  #
122
122
  # @api public
123
123
  def success?
124
- results.empty?
124
+ result_ast.empty?
125
125
  end
126
126
 
127
127
  # Check if the result is not successful
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "dry/initializer"
4
4
 
5
- require "dry/schema"
6
5
  require "dry/schema/constants"
7
6
  require "dry/schema/config"
8
7
  require "dry/schema/result"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.5.0"
5
+ VERSION = "1.5.5"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.5
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-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby