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 +4 -4
- data/CHANGELOG.md +61 -0
- data/lib/dry/schema/compiler.rb +1 -1
- data/lib/dry/schema/dsl.rb +0 -1
- data/lib/dry/schema/extensions/info/schema_compiler.rb +1 -1
- data/lib/dry/schema/key_validator.rb +4 -3
- data/lib/dry/schema/macros/value.rb +12 -2
- data/lib/dry/schema/message_compiler.rb +19 -2
- data/lib/dry/schema/path.rb +16 -1
- data/lib/dry/schema/predicate.rb +2 -0
- data/lib/dry/schema/result.rb +2 -2
- data/lib/dry/schema/rule_applier.rb +0 -1
- data/lib/dry/schema/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 442f6c2c04925f14ec6f0230394ad8e009518e9a2d7c1db22ddf68416324d530
|
4
|
+
data.tar.gz: 8f210323df91ba5ebf8a947b5888907b6f6f7cac504f93fbec80af8678dbdeb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87c2dcc7e169f2ff4c474038a0821a77e9f71420d40d2a4fe59f1d0ab722bcbbc3b9a60dcb33107d34d77cd303a82c33ebb3d084c350a49fc13e7b4cd73666f8
|
7
|
+
data.tar.gz: 59442e66361d9a1daf9de31480681bf0414875f22b9cdd440224db7b1a5fde818bdc479e2296cea558b00e9b698df56645aa65a55da59bb2bde2d67b4b979120
|
data/CHANGELOG.md
CHANGED
@@ -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
|
|
data/lib/dry/schema/compiler.rb
CHANGED
data/lib/dry/schema/dsl.rb
CHANGED
@@ -28,11 +28,11 @@ module Dry
|
|
28
28
|
if path[INDEX_REGEX]
|
29
29
|
key = path.gsub(INDEX_REGEX, BRACKETS)
|
30
30
|
|
31
|
-
|
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
|
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.
|
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
|
-
|
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, _|
|
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
|
-
|
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
|
data/lib/dry/schema/path.rb
CHANGED
@@ -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
|
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)
|
data/lib/dry/schema/predicate.rb
CHANGED
data/lib/dry/schema/result.rb
CHANGED
@@ -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
|
-
|
124
|
+
result_ast.empty?
|
125
125
|
end
|
126
126
|
|
127
127
|
# Check if the result is not successful
|
data/lib/dry/schema/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|