dry-schema 1.13.4 → 1.14.1
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 +20 -0
- data/README.md +1 -1
- data/config/errors.yml +9 -1
- data/dry-schema.gemspec +15 -17
- data/lib/dry/schema/config.rb +6 -6
- data/lib/dry/schema/constants.rb +2 -2
- data/lib/dry/schema/dsl.rb +18 -18
- data/lib/dry/schema/extensions/hints/message_compiler_methods.rb +1 -1
- data/lib/dry/schema/extensions/info/schema_compiler.rb +16 -7
- data/lib/dry/schema/extensions/json_schema/schema_compiler.rb +3 -3
- data/lib/dry/schema/extensions/monads.rb +1 -1
- data/lib/dry/schema/extensions/struct.rb +3 -3
- data/lib/dry/schema/key.rb +4 -4
- data/lib/dry/schema/key_coercer.rb +3 -3
- data/lib/dry/schema/key_map.rb +5 -5
- data/lib/dry/schema/key_validator.rb +19 -8
- data/lib/dry/schema/macros/dsl.rb +1 -1
- data/lib/dry/schema/macros/filled.rb +1 -2
- data/lib/dry/schema/macros/hash.rb +1 -1
- data/lib/dry/schema/macros/schema.rb +3 -3
- data/lib/dry/schema/macros/value.rb +12 -12
- data/lib/dry/schema/message.rb +4 -4
- data/lib/dry/schema/message_compiler.rb +8 -8
- data/lib/dry/schema/message_set.rb +8 -8
- data/lib/dry/schema/messages/abstract.rb +12 -12
- data/lib/dry/schema/messages/namespaced.rb +1 -1
- data/lib/dry/schema/messages/template.rb +2 -2
- data/lib/dry/schema/messages/yaml.rb +3 -3
- data/lib/dry/schema/path.rb +12 -12
- data/lib/dry/schema/predicate.rb +4 -4
- data/lib/dry/schema/predicate_registry.rb +2 -2
- data/lib/dry/schema/processor.rb +10 -10
- data/lib/dry/schema/processor_steps.rb +1 -1
- data/lib/dry/schema/result.rb +6 -6
- data/lib/dry/schema/rule_applier.rb +1 -1
- data/lib/dry/schema/trace.rb +1 -1
- data/lib/dry/schema/type_container.rb +2 -2
- data/lib/dry/schema/type_registry.rb +1 -1
- data/lib/dry/schema/types.rb +1 -1
- data/lib/dry/schema/types_merger.rb +18 -62
- data/lib/dry/schema/value_coercer.rb +1 -1
- data/lib/dry/schema/version.rb +1 -1
- data/lib/dry/schema.rb +11 -11
- metadata +20 -78
data/lib/dry/schema/message.rb
CHANGED
@@ -8,9 +8,9 @@ module Dry
|
|
8
8
|
#
|
9
9
|
# @api public
|
10
10
|
class Message
|
11
|
-
include Dry::Equalizer(:text, :path, :predicate, :input)
|
11
|
+
include ::Dry::Equalizer(:text, :path, :predicate, :input)
|
12
12
|
|
13
|
-
extend Dry::Initializer
|
13
|
+
extend ::Dry::Initializer
|
14
14
|
|
15
15
|
# @!attribute [r] text
|
16
16
|
# Message text representation created from a localized template
|
@@ -75,7 +75,7 @@ module Dry
|
|
75
75
|
#
|
76
76
|
# @api private
|
77
77
|
def eql?(other)
|
78
|
-
other.is_a?(String) ? text == other : super
|
78
|
+
other.is_a?(::String) ? text == other : super
|
79
79
|
end
|
80
80
|
|
81
81
|
# @api private
|
@@ -94,7 +94,7 @@ module Dry
|
|
94
94
|
r_path = other._path
|
95
95
|
|
96
96
|
unless l_path.same_root?(r_path)
|
97
|
-
raise ArgumentError, "Cannot compare messages from different root paths"
|
97
|
+
raise ::ArgumentError, "Cannot compare messages from different root paths"
|
98
98
|
end
|
99
99
|
|
100
100
|
l_path <=> r_path
|
@@ -9,7 +9,7 @@ module Dry
|
|
9
9
|
#
|
10
10
|
# @api private
|
11
11
|
class MessageCompiler
|
12
|
-
extend Dry::Initializer
|
12
|
+
extend ::Dry::Initializer
|
13
13
|
|
14
14
|
resolve_key_predicate = proc { |node, opts|
|
15
15
|
*arg_vals, val = node.map(&:last)
|
@@ -20,12 +20,12 @@ module Dry
|
|
20
20
|
[Array(opts.path), *node.map(&:last)]
|
21
21
|
}
|
22
22
|
|
23
|
-
DEFAULT_PREDICATE_RESOLVERS = Hash
|
23
|
+
DEFAULT_PREDICATE_RESOLVERS = ::Hash
|
24
24
|
.new(resolve_predicate).update(key?: resolve_key_predicate).freeze
|
25
25
|
|
26
26
|
EMPTY_OPTS = VisitorOpts.new
|
27
27
|
EMPTY_MESSAGE_SET = MessageSet.new(EMPTY_ARRAY).freeze
|
28
|
-
FULL_MESSAGE_WHITESPACE = Hash.new(" ").merge(
|
28
|
+
FULL_MESSAGE_WHITESPACE = ::Hash.new(" ").merge(
|
29
29
|
ja: "",
|
30
30
|
zh: "",
|
31
31
|
bn: "",
|
@@ -190,7 +190,7 @@ module Dry
|
|
190
190
|
def lookup_options(arg_vals:, input:)
|
191
191
|
default_lookup_options.merge(
|
192
192
|
arg_type: arg_vals.size == 1 && arg_vals[0].class,
|
193
|
-
val_type: input.equal?(Undefined) ? NilClass : input.class
|
193
|
+
val_type: input.equal?(Undefined) ? ::NilClass : input.class
|
194
194
|
)
|
195
195
|
end
|
196
196
|
|
@@ -209,11 +209,11 @@ module Dry
|
|
209
209
|
def message_tokens(args)
|
210
210
|
tokens = args.each_with_object({}) do |arg, hash|
|
211
211
|
case arg[1]
|
212
|
-
when Array
|
212
|
+
when ::Array, ::Set
|
213
213
|
hash[arg[0]] = arg[1].join(LIST_SEPARATOR)
|
214
|
-
when Range
|
215
|
-
hash["#{arg[0]}_left"
|
216
|
-
hash["#{arg[0]}_right"
|
214
|
+
when ::Range
|
215
|
+
hash[:"#{arg[0]}_left"] = arg[1].first
|
216
|
+
hash[:"#{arg[0]}_right"] = arg[1].last
|
217
217
|
else
|
218
218
|
hash[arg[0]] = arg[1]
|
219
219
|
end
|
@@ -10,8 +10,8 @@ module Dry
|
|
10
10
|
#
|
11
11
|
# @api public
|
12
12
|
class MessageSet
|
13
|
-
include Enumerable
|
14
|
-
include Dry::Equalizer(:messages, :options)
|
13
|
+
include ::Enumerable
|
14
|
+
include ::Dry::Equalizer(:messages, :options)
|
15
15
|
|
16
16
|
# A list of compiled message objects
|
17
17
|
#
|
@@ -44,11 +44,11 @@ module Dry
|
|
44
44
|
# @return [Array]
|
45
45
|
#
|
46
46
|
# @api public
|
47
|
-
def each(&
|
47
|
+
def each(&)
|
48
48
|
return self if empty?
|
49
|
-
return to_enum unless
|
49
|
+
return to_enum unless block_given?
|
50
50
|
|
51
|
-
messages.each(&
|
51
|
+
messages.each(&)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Dump message set to a hash
|
@@ -82,7 +82,7 @@ module Dry
|
|
82
82
|
#
|
83
83
|
# @api public
|
84
84
|
def fetch(key)
|
85
|
-
self[key] || raise(KeyError, "+#{key}+ message was not found")
|
85
|
+
self[key] || raise(::KeyError, "+#{key}+ message was not found")
|
86
86
|
end
|
87
87
|
|
88
88
|
# Check if a message set is empty
|
@@ -135,9 +135,9 @@ module Dry
|
|
135
135
|
# @api private
|
136
136
|
def partition_message_values(values)
|
137
137
|
values
|
138
|
-
.map { |value| value.is_a?(Array) ? value : [value] }
|
138
|
+
.map { |value| value.is_a?(::Array) ? value : [value] }
|
139
139
|
.reduce(EMPTY_ARRAY.dup, :+)
|
140
|
-
.partition { |value| value.is_a?(Hash) && !value[:text].is_a?(String) }
|
140
|
+
.partition { |value| value.is_a?(::Hash) && !value[:text].is_a?(::String) }
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
@@ -12,11 +12,11 @@ module Dry
|
|
12
12
|
#
|
13
13
|
# @api public
|
14
14
|
class Abstract
|
15
|
-
include Dry::Configurable
|
16
|
-
include Dry::Equalizer(:config)
|
15
|
+
include ::Dry::Configurable
|
16
|
+
include ::Dry::Equalizer(:config)
|
17
17
|
|
18
18
|
setting :default_locale
|
19
|
-
setting :load_paths, default: Set[DEFAULT_MESSAGES_PATH]
|
19
|
+
setting :load_paths, default: ::Set[DEFAULT_MESSAGES_PATH]
|
20
20
|
setting :top_namespace, default: DEFAULT_MESSAGES_ROOT
|
21
21
|
setting :root, default: "errors"
|
22
22
|
setting :lookup_options, default: %i[root predicate path val_type arg_type].freeze
|
@@ -34,13 +34,13 @@ module Dry
|
|
34
34
|
|
35
35
|
setting :rule_lookup_paths, default: ["rules.%<name>s"].freeze
|
36
36
|
|
37
|
-
setting :arg_types, default: Hash.new { |*| "default" }.update(
|
38
|
-
Range => "range"
|
37
|
+
setting :arg_types, default: ::Hash.new { |*| "default" }.update(
|
38
|
+
::Range => "range"
|
39
39
|
)
|
40
40
|
|
41
|
-
setting :val_types, default: Hash.new { |*| "default" }.update(
|
42
|
-
Range => "range",
|
43
|
-
String => "string"
|
41
|
+
setting :val_types, default: ::Hash.new { |*| "default" }.update(
|
42
|
+
::Range => "range",
|
43
|
+
::String => "string"
|
44
44
|
)
|
45
45
|
|
46
46
|
# @api private
|
@@ -80,7 +80,7 @@ module Dry
|
|
80
80
|
path = rule_lookup_paths(tokens).detect { |key| key?(key, options) }
|
81
81
|
|
82
82
|
rule = get(path, options) if path
|
83
|
-
rule.is_a?(Hash) ? rule[:text] : rule
|
83
|
+
rule.is_a?(::Hash) ? rule[:text] : rule
|
84
84
|
end
|
85
85
|
|
86
86
|
# Retrieve a message template
|
@@ -115,7 +115,7 @@ module Dry
|
|
115
115
|
#
|
116
116
|
# @api public
|
117
117
|
def key?(_key, _options = EMPTY_HASH)
|
118
|
-
raise NotImplementedError
|
118
|
+
raise ::NotImplementedError
|
119
119
|
end
|
120
120
|
|
121
121
|
# Retrieve an array of looked up paths
|
@@ -172,12 +172,12 @@ module Dry
|
|
172
172
|
|
173
173
|
# @api private
|
174
174
|
def interpolatable_data(_key, _options, **_data)
|
175
|
-
raise NotImplementedError
|
175
|
+
raise ::NotImplementedError
|
176
176
|
end
|
177
177
|
|
178
178
|
# @api private
|
179
179
|
def interpolate(_key, _options, **_data)
|
180
|
-
raise NotImplementedError
|
180
|
+
raise ::NotImplementedError
|
181
181
|
end
|
182
182
|
|
183
183
|
private
|
@@ -10,8 +10,8 @@ module Dry
|
|
10
10
|
module Messages
|
11
11
|
# @api private
|
12
12
|
class Template
|
13
|
-
extend Dry::Initializer
|
14
|
-
include Dry::Equalizer(:messages, :key, :options)
|
13
|
+
extend ::Dry::Initializer
|
14
|
+
include ::Dry::Equalizer(:messages, :key, :options)
|
15
15
|
|
16
16
|
option :messages
|
17
17
|
option :key
|
@@ -14,7 +14,7 @@ module Dry
|
|
14
14
|
class YAML < Abstract
|
15
15
|
LOCALE_TOKEN = "%<locale>s"
|
16
16
|
TOKEN_REGEXP = /%{(\w*)}/
|
17
|
-
EMPTY_CONTEXT = Object.new.tap { |ctx|
|
17
|
+
EMPTY_CONTEXT = ::Object.new.tap { |ctx|
|
18
18
|
def ctx.context
|
19
19
|
binding
|
20
20
|
end
|
@@ -165,12 +165,12 @@ module Dry
|
|
165
165
|
# @api private
|
166
166
|
def evaluation_context(key, options)
|
167
167
|
cache.fetch_or_store(get(key, options).fetch(:text)) do |input|
|
168
|
-
tokens = input.scan(TOKEN_REGEXP).flatten(1).
|
168
|
+
tokens = input.scan(TOKEN_REGEXP).flatten(1).to_set(&:to_sym)
|
169
169
|
text = input.gsub("%", "#")
|
170
170
|
|
171
171
|
# rubocop:disable Security/Eval
|
172
172
|
evaluator = eval(<<~RUBY, EMPTY_CONTEXT, __FILE__, __LINE__ + 1)
|
173
|
-
-> (#{tokens.map { |token| "#{token}:" }.join(", ")}) { "#{text}" }
|
173
|
+
-> (#{tokens.map { |token| "#{token}:" }.join(", ")}) { "#{text}" } # -> (a:, b:) { "Translation #\{a} #\{b}" }
|
174
174
|
RUBY
|
175
175
|
# rubocop:enable Security/Eval
|
176
176
|
|
data/lib/dry/schema/path.rb
CHANGED
@@ -8,9 +8,9 @@ module Dry
|
|
8
8
|
#
|
9
9
|
# @api private
|
10
10
|
class Path
|
11
|
-
include Dry.Equalizer(:keys)
|
12
|
-
include Comparable
|
13
|
-
include Enumerable
|
11
|
+
include ::Dry.Equalizer(:keys)
|
12
|
+
include ::Comparable
|
13
|
+
include ::Enumerable
|
14
14
|
|
15
15
|
# @return [Array<Symbol>]
|
16
16
|
attr_reader :keys
|
@@ -26,16 +26,16 @@ module Dry
|
|
26
26
|
# @api private
|
27
27
|
def self.call(spec)
|
28
28
|
case spec
|
29
|
-
when Symbol, Array
|
30
|
-
new(
|
31
|
-
when String
|
29
|
+
when ::Symbol, ::Array
|
30
|
+
new([*spec])
|
31
|
+
when ::String
|
32
32
|
new(spec.split(DOT).map(&:to_sym))
|
33
|
-
when Hash
|
33
|
+
when ::Hash
|
34
34
|
new(keys_from_hash(spec))
|
35
35
|
when self
|
36
36
|
spec
|
37
37
|
else
|
38
|
-
raise ArgumentError, "+spec+ must be either a Symbol, Array, Hash or a #{name}"
|
38
|
+
raise ::ArgumentError, "+spec+ must be either a Symbol, Array, Hash or a #{name}"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -49,7 +49,7 @@ module Dry
|
|
49
49
|
# @api private
|
50
50
|
def self.keys_from_hash(hash)
|
51
51
|
hash.inject([]) { |a, (k, v)|
|
52
|
-
v.is_a?(Hash) ? a.
|
52
|
+
v.is_a?(::Hash) ? a.push(k, *keys_from_hash(v)) : a.push(k, v)
|
53
53
|
}
|
54
54
|
end
|
55
55
|
|
@@ -60,14 +60,14 @@ module Dry
|
|
60
60
|
|
61
61
|
# @api private
|
62
62
|
def to_h(value = EMPTY_ARRAY.dup)
|
63
|
-
value = [value] unless value.is_a?(Array)
|
63
|
+
value = [value] unless value.is_a?(::Array)
|
64
64
|
|
65
65
|
keys.reverse_each.reduce(value) { |result, key| {key => result} }
|
66
66
|
end
|
67
67
|
|
68
68
|
# @api private
|
69
|
-
def each(&
|
70
|
-
keys.each(&
|
69
|
+
def each(&)
|
70
|
+
keys.each(&)
|
71
71
|
end
|
72
72
|
|
73
73
|
# @api private
|
data/lib/dry/schema/predicate.rb
CHANGED
@@ -13,7 +13,7 @@ module Dry
|
|
13
13
|
#
|
14
14
|
# @api private
|
15
15
|
class Negation
|
16
|
-
include Dry::Logic::Operators
|
16
|
+
include ::Dry::Logic::Operators
|
17
17
|
|
18
18
|
# @api private
|
19
19
|
attr_reader :predicate
|
@@ -34,8 +34,8 @@ module Dry
|
|
34
34
|
alias_method :ast, :to_ast
|
35
35
|
end
|
36
36
|
|
37
|
-
include Dry::Logic::Operators
|
38
|
-
include Dry::Equalizer(:name, :args, :block)
|
37
|
+
include ::Dry::Logic::Operators
|
38
|
+
include ::Dry::Equalizer(:name, :args, :block)
|
39
39
|
|
40
40
|
# @api private
|
41
41
|
attr_reader :compiler
|
@@ -77,7 +77,7 @@ module Dry
|
|
77
77
|
# @api private
|
78
78
|
def ensure_valid
|
79
79
|
if arity - 1 != args.size
|
80
|
-
raise ArgumentError, "#{name} predicate arity is invalid"
|
80
|
+
raise ::ArgumentError, "#{name} predicate arity is invalid"
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -5,7 +5,7 @@ module Dry
|
|
5
5
|
# A registry with predicate objects from `Dry::Logic::Predicates`
|
6
6
|
#
|
7
7
|
# @api private
|
8
|
-
class PredicateRegistry < Dry::Types::PredicateRegistry
|
8
|
+
class PredicateRegistry < ::Dry::Types::PredicateRegistry
|
9
9
|
# @api private
|
10
10
|
def arg_list(name, *values)
|
11
11
|
predicate = self[name]
|
@@ -15,7 +15,7 @@ module Dry
|
|
15
15
|
predicate
|
16
16
|
.parameters
|
17
17
|
.map(&:last)
|
18
|
-
.zip(values + Array.new(arity - values.size, Undefined))
|
18
|
+
.zip(values + ::Array.new(arity - values.size, Undefined))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/dry/schema/processor.rb
CHANGED
@@ -13,10 +13,10 @@ module Dry
|
|
13
13
|
#
|
14
14
|
# @api public
|
15
15
|
class Processor
|
16
|
-
extend Dry::Initializer
|
17
|
-
extend Dry::Configurable
|
16
|
+
extend ::Dry::Initializer
|
17
|
+
extend ::Dry::Configurable
|
18
18
|
|
19
|
-
include Dry::Logic::Operators
|
19
|
+
include ::Dry::Logic::Operators
|
20
20
|
|
21
21
|
setting :key_map_type
|
22
22
|
setting :type_registry_namespace, default: :strict
|
@@ -42,9 +42,9 @@ module Dry
|
|
42
42
|
# @return [Class]
|
43
43
|
#
|
44
44
|
# @api public
|
45
|
-
def define(&
|
45
|
+
def define(&)
|
46
46
|
@definition ||= DSL.new(
|
47
|
-
processor_type: self, parent: superclass.definition, **config.to_h, &
|
47
|
+
processor_type: self, parent: superclass.definition, **config.to_h, &
|
48
48
|
)
|
49
49
|
self
|
50
50
|
end
|
@@ -54,15 +54,15 @@ module Dry
|
|
54
54
|
# @return [Processor]
|
55
55
|
#
|
56
56
|
# @api public
|
57
|
-
def new(options = nil
|
58
|
-
if options ||
|
57
|
+
def new(options = nil)
|
58
|
+
if options || block_given?
|
59
59
|
processor = super(**(options || EMPTY_HASH))
|
60
|
-
yield(processor) if
|
60
|
+
yield(processor) if block_given?
|
61
61
|
processor
|
62
62
|
elsif definition
|
63
63
|
definition.call
|
64
64
|
else
|
65
|
-
raise ArgumentError, "Cannot create a schema without a definition"
|
65
|
+
raise ::ArgumentError, "Cannot create a schema without a definition"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -83,7 +83,7 @@ module Dry
|
|
83
83
|
|
84
84
|
# @api public
|
85
85
|
def xor(_other)
|
86
|
-
raise NotImplementedError, "composing schemas using `xor` operator is not supported yet"
|
86
|
+
raise ::NotImplementedError, "composing schemas using `xor` operator is not supported yet"
|
87
87
|
end
|
88
88
|
alias_method :^, :xor
|
89
89
|
|
data/lib/dry/schema/result.rb
CHANGED
@@ -11,9 +11,9 @@ module Dry
|
|
11
11
|
#
|
12
12
|
# @api public
|
13
13
|
class Result
|
14
|
-
include Dry::Equalizer(:output, :errors)
|
14
|
+
include ::Dry::Equalizer(:output, :errors)
|
15
15
|
|
16
|
-
extend Dry::Initializer[undefined: false]
|
16
|
+
extend ::Dry::Initializer[undefined: false]
|
17
17
|
|
18
18
|
# @api private
|
19
19
|
param :output, reader: false
|
@@ -43,18 +43,18 @@ module Dry
|
|
43
43
|
# @return [Result]
|
44
44
|
#
|
45
45
|
# @api private
|
46
|
-
def at(at_path, &
|
47
|
-
new(@output, path: Path.new([*path, *Path[at_path]]), &
|
46
|
+
def at(at_path, &)
|
47
|
+
new(@output, path: Path.new([*path, *Path[at_path]]), &)
|
48
48
|
end
|
49
49
|
|
50
50
|
# @api private
|
51
|
-
def new(output, **opts, &
|
51
|
+
def new(output, **opts, &)
|
52
52
|
self.class.new(
|
53
53
|
output,
|
54
54
|
message_compiler: message_compiler,
|
55
55
|
result_ast: result_ast,
|
56
56
|
**opts,
|
57
|
-
&
|
57
|
+
&
|
58
58
|
)
|
59
59
|
end
|
60
60
|
|
data/lib/dry/schema/trace.rb
CHANGED
@@ -13,9 +13,9 @@ module Dry
|
|
13
13
|
#
|
14
14
|
# @api public
|
15
15
|
class TypeContainer
|
16
|
-
include Dry::Core::Container::Mixin
|
16
|
+
include ::Dry::Core::Container::Mixin
|
17
17
|
|
18
|
-
def initialize(types_container = Dry::Types.container)
|
18
|
+
def initialize(types_container = ::Dry::Types.container)
|
19
19
|
super()
|
20
20
|
|
21
21
|
merge(types_container)
|
data/lib/dry/schema/types.rb
CHANGED
@@ -27,14 +27,14 @@ module Dry
|
|
27
27
|
|
28
28
|
# @api private
|
29
29
|
def call
|
30
|
-
if op_class <= Dry::Logic::Operations::Or
|
30
|
+
if op_class <= ::Dry::Logic::Operations::Or
|
31
31
|
merge_or
|
32
|
-
elsif op_class <= Dry::Logic::Operations::And
|
32
|
+
elsif op_class <= ::Dry::Logic::Operations::And
|
33
33
|
merge_and
|
34
|
-
elsif op_class <= Dry::Logic::Operations::Implication
|
34
|
+
elsif op_class <= ::Dry::Logic::Operations::Implication
|
35
35
|
merge_implication
|
36
36
|
else
|
37
|
-
raise ArgumentError, <<~MESSAGE
|
37
|
+
raise ::ArgumentError, <<~MESSAGE
|
38
38
|
Can't merge operations, op_class=#{op_class}
|
39
39
|
MESSAGE
|
40
40
|
end
|
@@ -58,7 +58,7 @@ module Dry
|
|
58
58
|
|
59
59
|
rule = [old_rule, new_rule].compact.reduce { op_class.new(_1, _2) }
|
60
60
|
|
61
|
-
type = Dry::Types::Constrained.new(type, rule: rule) if rule
|
61
|
+
type = ::Dry::Types::Constrained.new(type, rule: rule) if rule
|
62
62
|
|
63
63
|
type
|
64
64
|
end
|
@@ -66,61 +66,17 @@ module Dry
|
|
66
66
|
alias_method :merge_and, :merge_ordered
|
67
67
|
alias_method :merge_implication, :merge_ordered
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
else
|
81
|
-
merge_equivalent_types(unwrapped_old, unwrapped_new)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
else
|
86
|
-
# @api private
|
87
|
-
def merge_unwrapped_types(unwrapped_old, unwrapped_new)
|
88
|
-
if change_from_schema_to_schema?(unwrapped_old, unwrapped_new)
|
89
|
-
merge_schemas(unwrapped_old, unwrapped_new)
|
90
|
-
elsif change_from_any?(unwrapped_old) || change_from_hash_to_schema?(unwrapped_old,
|
91
|
-
unwrapped_new)
|
92
|
-
unwrapped_new
|
93
|
-
elsif change_from_schema_to_hash?(unwrapped_old,
|
94
|
-
unwrapped_new) || change_to_any?(unwrapped_new)
|
95
|
-
unwrapped_old
|
96
|
-
else
|
97
|
-
merge_equivalent_types(unwrapped_old, unwrapped_new)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# @api private
|
102
|
-
def change_from_any?(unwrapped_old)
|
103
|
-
unwrapped_old.is_a?(Dry::Types::AnyClass)
|
104
|
-
end
|
105
|
-
|
106
|
-
# @api private
|
107
|
-
def change_to_any?(unwrapped_new)
|
108
|
-
unwrapped_new.is_a?(Dry::Types::AnyClass)
|
109
|
-
end
|
110
|
-
|
111
|
-
# @api private
|
112
|
-
def change_from_hash_to_schema?(unwrapped_old, unwrapped_new)
|
113
|
-
unwrapped_old.is_a?(Dry::Types::Hash) && unwrapped_new.is_a?(Dry::Types::Schema)
|
114
|
-
end
|
115
|
-
|
116
|
-
# @api private
|
117
|
-
def change_from_schema_to_hash?(unwrapped_old, unwrapped_new)
|
118
|
-
unwrapped_old.is_a?(Dry::Types::Schema) && unwrapped_new.is_a?(Dry::Types::Hash)
|
119
|
-
end
|
120
|
-
|
121
|
-
# @api private
|
122
|
-
def change_from_schema_to_schema?(unwrapped_old, unwrapped_new)
|
123
|
-
unwrapped_old.is_a?(Dry::Types::Schema) && unwrapped_new.is_a?(Dry::Types::Schema)
|
69
|
+
# @api private
|
70
|
+
def merge_unwrapped_types(unwrapped_old, unwrapped_new)
|
71
|
+
case [unwrapped_old, unwrapped_new]
|
72
|
+
in ::Dry::Types::Schema, ::Dry::Types::Schema
|
73
|
+
merge_schemas(unwrapped_old, unwrapped_new)
|
74
|
+
in [::Dry::Types::AnyClass, _] | [::Dry::Types::Hash, ::Dry::Types::Schema]
|
75
|
+
unwrapped_new
|
76
|
+
in [::Dry::Types::Schema, ::Dry::Types::Hash] | [_, ::Dry::Types::AnyClass]
|
77
|
+
unwrapped_old
|
78
|
+
else
|
79
|
+
merge_equivalent_types(unwrapped_old, unwrapped_new)
|
124
80
|
end
|
125
81
|
end
|
126
82
|
|
@@ -142,7 +98,7 @@ module Dry
|
|
142
98
|
elsif unwrapped_new.primitive <= unwrapped_old.primitive
|
143
99
|
unwrapped_old
|
144
100
|
else
|
145
|
-
raise ArgumentError, <<~MESSAGE
|
101
|
+
raise ::ArgumentError, <<~MESSAGE
|
146
102
|
Can't merge types, unwrapped_old=#{unwrapped_old.inspect}, unwrapped_new=#{unwrapped_new.inspect}
|
147
103
|
MESSAGE
|
148
104
|
end
|
@@ -157,7 +113,7 @@ module Dry
|
|
157
113
|
|
158
114
|
if type.optional?
|
159
115
|
type = type.left.primitive?(nil) ? type.right : type.left
|
160
|
-
elsif type.is_a?(Dry::Types::Decorator)
|
116
|
+
elsif type.is_a?(::Dry::Types::Decorator)
|
161
117
|
type = type.type
|
162
118
|
else
|
163
119
|
break
|