dry-schema 1.3.1 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/config/errors.yml +9 -0
- data/lib/dry/schema/macros/dsl.rb +6 -0
- data/lib/dry/schema/macros/filled.rb +0 -6
- data/lib/dry/schema/macros/schema.rb +2 -7
- data/lib/dry/schema/macros/value.rb +21 -2
- data/lib/dry/schema/messages/abstract.rb +10 -1
- data/lib/dry/schema/messages/i18n.rb +9 -0
- data/lib/dry/schema/messages/namespaced.rb +5 -0
- data/lib/dry/schema/namespaced_rule.rb +2 -1
- data/lib/dry/schema/primitive_inferrer.rb +1 -0
- data/lib/dry/schema/processor.rb +1 -1
- data/lib/dry/schema/type_registry.rb +2 -2
- 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: a05f28f075af158f47da3ead0ea7441c8408d6d3aa9473481e47ceecdb94263f
|
4
|
+
data.tar.gz: a326e62e9af7360654a61204096d636acda23eabd497a1d2c847fc4afe8cfa98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b360914840bf0a6db5d5e3c2ba7464077ddc2c21664758256ef06f054e8a4a9fddc53fe8a13fc5a3456fb2794ac84051496471826ef49fb293a51074d2b9abf
|
7
|
+
data.tar.gz: '09862ce9b446d84a507846a47435c1d82d483531940fd6dc6bc6244bccf22cca430673a589950c74bbcbec35a771b01a5ffd00ac37decd256057e5da618ff8e9'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# 1.3.3 2019-08-14
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* Reject attempts to build a nested schema for array types built on `Dry::Types::Nominal` (fixed #171) (@flash-gordon)
|
6
|
+
* Current `I18n.locale` is now properly handled when caching message templates (@flash-gordon)
|
7
|
+
* Default processor uses strict types by default, which fixes various cases when `maybe` is used with a constructor type (@flash-gordon)
|
8
|
+
* Namespaced messages no longer causes a crash when used with nested schemas (fixed #176) (@solnic)
|
9
|
+
|
10
|
+
[Compare v1.3.2...v1.3.3](https://github.com/dry-rb/dry-schema/compare/v1.3.2...v1.3.3)
|
11
|
+
|
12
|
+
# 1.3.2 2019-08-01
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
* Support for new predicates: `bytesize?`, `min_bytesize?` and `max_bytesize?` (@bmalinconico)
|
17
|
+
|
18
|
+
[Compare v1.3.1...v1.3.2](https://github.com/dry-rb/dry-schema/compare/v1.3.1...v1.3.2)
|
19
|
+
|
1
20
|
# 1.3.1 2019-07-08
|
2
21
|
|
3
22
|
### Fixed
|
data/config/errors.yml
CHANGED
@@ -73,8 +73,12 @@ en:
|
|
73
73
|
|
74
74
|
max_size?: "size cannot be greater than %{num}"
|
75
75
|
|
76
|
+
max_bytesize?: "bytesize cannot be greater than %{num}"
|
77
|
+
|
76
78
|
min_size?: "size cannot be less than %{num}"
|
77
79
|
|
80
|
+
min_bytesize?: "bytesize cannot be less than %{num}"
|
81
|
+
|
78
82
|
nil?: "cannot be defined"
|
79
83
|
|
80
84
|
str?: "must be a string"
|
@@ -92,5 +96,10 @@ en:
|
|
92
96
|
default: "length must be %{size}"
|
93
97
|
range: "length must be within %{size_left} - %{size_right}"
|
94
98
|
|
99
|
+
bytesize?:
|
100
|
+
arg:
|
101
|
+
default: "must be %{size} bytes long"
|
102
|
+
range: "must be within %{size_left} - %{size_right} bytes long"
|
103
|
+
|
95
104
|
not:
|
96
105
|
empty?: "cannot be empty"
|
@@ -28,6 +28,12 @@ module Dry
|
|
28
28
|
# @api private
|
29
29
|
option :predicate_inferrer, default: proc { PredicateInferrer.new(compiler.predicates) }
|
30
30
|
|
31
|
+
# @!attribute [r] primitive_inferrer
|
32
|
+
# PrimitiveInferrer used to get a list of primitive classes from configured type
|
33
|
+
# @return [PrimitiveInferrer]
|
34
|
+
# @api private
|
35
|
+
option :primitive_inferrer, default: proc { PrimitiveInferrer.new }
|
36
|
+
|
31
37
|
# @overload value(*predicates, **predicate_opts)
|
32
38
|
# Set predicates without and with arguments
|
33
39
|
#
|
@@ -10,12 +10,6 @@ module Dry
|
|
10
10
|
#
|
11
11
|
# @api private
|
12
12
|
class Filled < Value
|
13
|
-
# @!attribute [r] primitive_inferrer
|
14
|
-
# PrimitiveInferrer used to get a list of primitive classes from configured type
|
15
|
-
# @return [PrimitiveInferrer]
|
16
|
-
# @api private
|
17
|
-
option :primitive_inferrer, default: proc { PrimitiveInferrer.new }
|
18
|
-
|
19
13
|
# @api private
|
20
14
|
def call(*predicates, **opts, &block)
|
21
15
|
ensure_valid_predicates(predicates)
|
@@ -28,8 +28,8 @@ module Dry
|
|
28
28
|
definition = schema_dsl.new(&block)
|
29
29
|
schema = definition.call
|
30
30
|
type_schema =
|
31
|
-
if array?
|
32
|
-
parent_type
|
31
|
+
if array?(parent_type)
|
32
|
+
build_array_type(parent_type, definition.type_schema)
|
33
33
|
elsif redefined_schema?(args)
|
34
34
|
parent_type.schema(definition.types)
|
35
35
|
else
|
@@ -56,11 +56,6 @@ module Dry
|
|
56
56
|
parent_type.optional?
|
57
57
|
end
|
58
58
|
|
59
|
-
# @api private
|
60
|
-
def array?
|
61
|
-
parent_type.respond_to?(:of)
|
62
|
-
end
|
63
|
-
|
64
59
|
# @api private
|
65
60
|
def schema?
|
66
61
|
parent_type.respond_to?(:schema)
|
@@ -17,8 +17,8 @@ module Dry
|
|
17
17
|
current_type = schema_dsl.types[name]
|
18
18
|
|
19
19
|
updated_type =
|
20
|
-
if
|
21
|
-
current_type
|
20
|
+
if array?(current_type)
|
21
|
+
build_array_type(current_type, schema.type_schema)
|
22
22
|
else
|
23
23
|
schema.type_schema
|
24
24
|
end
|
@@ -39,6 +39,25 @@ module Dry
|
|
39
39
|
self
|
40
40
|
end
|
41
41
|
|
42
|
+
# @api private
|
43
|
+
def array?(type)
|
44
|
+
primitive_inferrer[type].eql?([::Array])
|
45
|
+
end
|
46
|
+
|
47
|
+
# @api private
|
48
|
+
def build_array_type(array_type, member)
|
49
|
+
if array_type.respond_to?(:of)
|
50
|
+
array_type.of(member)
|
51
|
+
else
|
52
|
+
raise ArgumentError, <<~ERROR.split("\n").join(' ')
|
53
|
+
Cannot define schema for a nominal array type.
|
54
|
+
Array types must be instances of Dry::Types::Array,
|
55
|
+
usually constructed with Types::Constructor(Array) { ... } or
|
56
|
+
Dry::Types['array'].constructor { ... }
|
57
|
+
ERROR
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
42
61
|
# @api private
|
43
62
|
def respond_to_missing?(meth, include_private = false)
|
44
63
|
super || meth.to_s.end_with?(QUESTION_MARK)
|
@@ -92,7 +92,7 @@ module Dry
|
|
92
92
|
#
|
93
93
|
# @api public
|
94
94
|
def call(predicate, options)
|
95
|
-
cache.fetch_or_store(
|
95
|
+
cache.fetch_or_store(cache_key(predicate, options)) do
|
96
96
|
text, meta = lookup(predicate, options)
|
97
97
|
[Template[text], meta] if text
|
98
98
|
end
|
@@ -167,6 +167,15 @@ module Dry
|
|
167
167
|
config.default_locale
|
168
168
|
end
|
169
169
|
|
170
|
+
# @api private
|
171
|
+
def cache_key(predicate, options)
|
172
|
+
if options.key?(:input)
|
173
|
+
[predicate, options.reject { |k,| k.equal?(:input) }]
|
174
|
+
else
|
175
|
+
[predicate, options]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
170
179
|
private
|
171
180
|
|
172
181
|
# @api private
|
@@ -64,6 +64,11 @@ module Dry
|
|
64
64
|
base_paths = messages.rule_lookup_paths(tokens)
|
65
65
|
base_paths.map { |key| key.gsub('dry_schema', "dry_schema.#{namespace}") } + base_paths
|
66
66
|
end
|
67
|
+
|
68
|
+
# @api private
|
69
|
+
def cache_key(predicate, options)
|
70
|
+
messages.cache_key(predicate, options)
|
71
|
+
end
|
67
72
|
end
|
68
73
|
end
|
69
74
|
end
|
data/lib/dry/schema/processor.rb
CHANGED
@@ -18,12 +18,12 @@ module Dry
|
|
18
18
|
attr_reader :namespace
|
19
19
|
|
20
20
|
# @api private
|
21
|
-
def self.new(types = Dry::Types, namespace = :
|
21
|
+
def self.new(types = Dry::Types, namespace = :strict)
|
22
22
|
super
|
23
23
|
end
|
24
24
|
|
25
25
|
# @api private
|
26
|
-
def initialize(types, namespace = :
|
26
|
+
def initialize(types, namespace = :strict)
|
27
27
|
@types = types
|
28
28
|
@namespace = namespace
|
29
29
|
end
|
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.3.
|
4
|
+
version: 1.3.3
|
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-
|
11
|
+
date: 2019-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|