checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA256:
3
- metadata.gz: '09bdaec12d22913780786013c56defc8bdda2551ae564d1a4267e8a57aecd52f'
4
- data.tar.gz: 0b1af5392034213bbec06167860abc37dcb61ee9397bb2bd33fec2868d6bb1ef
3
+ metadata.gz: a05f28f075af158f47da3ead0ea7441c8408d6d3aa9473481e47ceecdb94263f
4
+ data.tar.gz: a326e62e9af7360654a61204096d636acda23eabd497a1d2c847fc4afe8cfa98
5
5
SHA512:
6
- metadata.gz: df1c3a36d836d4e31498f05fae0e27f3975a8b9b839ac4ebf6b92b6c5faa12b44b8715db18bb87d668dc61c669d9a59b04599ed7298387f12bac1eb34676647f
7
- data.tar.gz: b3b3540b8f4b7fa4a6b270858b0940e7d9fe225fab3be57952ab727b5aa78fd4a0fa3233d7993684a5cbcba95524e614b5b8b62a55bf30fd188c7ee742b99e9f
6
+ metadata.gz: 8b360914840bf0a6db5d5e3c2ba7464077ddc2c21664758256ef06f054e8a4a9fddc53fe8a13fc5a3456fb2794ac84051496471826ef49fb293a51074d2b9abf
7
+ data.tar.gz: '09862ce9b446d84a507846a47435c1d82d483531940fd6dc6bc6244bccf22cca430673a589950c74bbcbec35a771b01a5ffd00ac37decd256057e5da618ff8e9'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
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
+
1
12
# 1.3.2 2019-08-01
2
13
3
14
### Added
data/lib/dry/schema/macros/dsl.rb CHANGED
@@ -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
#
data/lib/dry/schema/macros/filled.rb CHANGED
@@ -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)
data/lib/dry/schema/macros/schema.rb CHANGED
@@ -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.of(definition.type_schema)
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
@@ -57,11 +57,6 @@ module Dry
57
57
end
58
58
59
59
# @api private
60
- def array?
61
- parent_type.respond_to?(:of)
62
- end
63
-
64
- # @api private
65
60
def schema?
66
61
parent_type.respond_to?(:schema)
67
62
end
data/lib/dry/schema/macros/value.rb CHANGED
@@ -17,8 +17,8 @@ module Dry
17
17
current_type = schema_dsl.types[name]
18
18
19
19
updated_type =
20
- if current_type.respond_to?(:of)
21
- current_type.of(schema.type_schema)
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
@@ -40,6 +40,25 @@ module Dry
40
40
end
41
41
42
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
+
61
+ # @api private
43
62
def respond_to_missing?(meth, include_private = false)
44
63
super || meth.to_s.end_with?(QUESTION_MARK)
45
64
end
data/lib/dry/schema/messages/abstract.rb CHANGED
@@ -92,7 +92,7 @@ module Dry
92
92
#
93
93
# @api public
94
94
def call(predicate, options)
95
- cache.fetch_or_store([predicate, options.reject { |k,| k.equal?(:input) }]) do
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
data/lib/dry/schema/messages/i18n.rb CHANGED
@@ -79,6 +79,15 @@ module Dry
79
79
self
80
80
end
81
81
82
+ # @api private
83
+ def cache_key(predicate, options)
84
+ if options[:locale]
85
+ super
86
+ else
87
+ [*super, I18n.locale]
88
+ end
89
+ end
90
+
82
91
private
83
92
84
93
# @api private
data/lib/dry/schema/messages/namespaced.rb CHANGED
@@ -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/namespaced_rule.rb CHANGED
@@ -29,9 +29,10 @@ module Dry
29
29
end
30
30
31
31
# @api private
32
- def ast(input=Undefined)
32
+ def ast(input = Undefined)
33
33
[:namespace, [namespace, rule.ast(input)]]
34
34
end
35
+ alias_method :to_ast, :ast
35
36
end
36
37
end
37
38
end
data/lib/dry/schema/primitive_inferrer.rb CHANGED
@@ -32,6 +32,7 @@ module Dry
32
32
def visit_hash(_)
33
33
Hash
34
34
end
35
+ alias_method :visit_schema, :visit_hash
35
36
36
37
# @api private
37
38
def visit_array(_)
data/lib/dry/schema/processor.rb CHANGED
@@ -29,7 +29,7 @@ module Dry
29
29
extend Dry::Configurable
30
30
31
31
setting :key_map_type
32
- setting :type_registry_namespace, :nominal
32
+ setting :type_registry_namespace, :strict
33
33
setting :filter_empty_string, false
34
34
35
35
option :steps, default: -> { EMPTY_ARRAY.dup }
data/lib/dry/schema/type_registry.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 = :nominal)
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 = :nominal)
26
+ def initialize(types, namespace = :strict)
27
27
@types = types
28
28
@namespace = namespace
29
29
end
data/lib/dry/schema/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
3
3
module Dry
4
4
module Schema
5
- VERSION = '1.3.2'
5
+ VERSION = '1.3.3'
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.3.2
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-08-01 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
dependencies:
13
13
- !ruby/object:Gem::Dependency
14
14
name: concurrent-ruby
nijikon

nijikon

mensfeld

mensfeld