dry-schema 1.5.4 → 1.5.5

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: c6bd0ccbd94f361dc0e001b71fc4d1dbd76d00605a4d57c7e6fe06788235c0f0
4
- data.tar.gz: 29b3eb25a1ede9775dd331752a6abc51d2fd617764e14611899e8b07fb6f7ee8
3
+ metadata.gz: 442f6c2c04925f14ec6f0230394ad8e009518e9a2d7c1db22ddf68416324d530
4
+ data.tar.gz: 8f210323df91ba5ebf8a947b5888907b6f6f7cac504f93fbec80af8678dbdeb1
5
5
  SHA512:
6
- metadata.gz: 96f5e58a3ae138e6461d33e7e2bd030655191a6f8132c0d5adada3195d35f03b011b94d79c085fe0567a299caf63859349948ee0d8e06b73ac0a7a480f6d2db9
7
- data.tar.gz: c89a7b623c5ac5fc1cad6b880a4c02b892af9efad76c99e7803b0e0115a26445cf1d35d1bba4518f0186fc4d36fa6a8bf26de64ed9e9f74513f35b1e7aac04f4
6
+ metadata.gz: 87c2dcc7e169f2ff4c474038a0821a77e9f71420d40d2a4fe59f1d0ab722bcbbc3b9a60dcb33107d34d77cd303a82c33ebb3d084c350a49fc13e7b4cd73666f8
7
+ data.tar.gz: 59442e66361d9a1daf9de31480681bf0414875f22b9cdd440224db7b1a5fde818bdc479e2296cea558b00e9b698df56645aa65a55da59bb2bde2d67b4b979120
@@ -1,3 +1,15 @@
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
+
1
13
  ## 1.5.4
2
14
 
3
15
  2020-09-03
@@ -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)
@@ -116,6 +116,7 @@ module Dry
116
116
 
117
117
  Message.new(
118
118
  path: path,
119
+ meta: msg[:meta] || EMPTY_HASH,
119
120
  text: msg[:text],
120
121
  predicate: nil,
121
122
  input: input
@@ -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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.5.4"
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.4
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-09-03 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