dry-types 1.7.1 → 1.8.0
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 +28 -0
- data/README.md +3 -2
- data/dry-types.gemspec +12 -15
- data/lib/dry/types/any.rb +3 -9
- data/lib/dry/types/array/constructor.rb +3 -9
- data/lib/dry/types/array/member.rb +1 -3
- data/lib/dry/types/array.rb +1 -1
- data/lib/dry/types/builder.rb +19 -35
- data/lib/dry/types/builder_methods.rb +5 -15
- data/lib/dry/types/coercions/json.rb +3 -3
- data/lib/dry/types/coercions/params.rb +13 -13
- data/lib/dry/types/coercions.rb +13 -15
- data/lib/dry/types/compiler.rb +5 -7
- data/lib/dry/types/composition.rb +17 -31
- data/lib/dry/types/constrained.rb +31 -23
- data/lib/dry/types/constructor/function.rb +19 -31
- data/lib/dry/types/constructor/wrapper.rb +5 -11
- data/lib/dry/types/constructor.rb +9 -17
- data/lib/dry/types/core.rb +14 -6
- data/lib/dry/types/decorator.rb +7 -18
- data/lib/dry/types/default.rb +12 -16
- data/lib/dry/types/enum.rb +33 -13
- data/lib/dry/types/errors.rb +4 -8
- data/lib/dry/types/extensions/maybe.rb +4 -10
- data/lib/dry/types/fn_container.rb +3 -3
- data/lib/dry/types/hash/constructor.rb +3 -9
- data/lib/dry/types/hash.rb +8 -6
- data/lib/dry/types/implication.rb +3 -5
- data/lib/dry/types/inflector.rb +1 -1
- data/lib/dry/types/intersection.rb +3 -9
- data/lib/dry/types/lax.rb +4 -10
- data/lib/dry/types/map.rb +33 -41
- data/lib/dry/types/meta.rb +2 -6
- data/lib/dry/types/module.rb +3 -5
- data/lib/dry/types/nominal.rb +13 -35
- data/lib/dry/types/predicate_inferrer.rb +7 -4
- data/lib/dry/types/predicate_registry.rb +1 -3
- data/lib/dry/types/primitive_inferrer.rb +4 -12
- data/lib/dry/types/printable.rb +1 -3
- data/lib/dry/types/printer/composition.rb +3 -3
- data/lib/dry/types/printer.rb +6 -9
- data/lib/dry/types/result.rb +5 -15
- data/lib/dry/types/schema/key.rb +11 -26
- data/lib/dry/types/schema.rb +10 -12
- data/lib/dry/types/spec/types.rb +2 -2
- data/lib/dry/types/sum.rb +4 -8
- data/lib/dry/types/type.rb +2 -2
- data/lib/dry/types/version.rb +1 -1
- data/lib/dry/types.rb +3 -3
- metadata +22 -63
data/lib/dry/types/enum.rb
CHANGED
@@ -7,7 +7,7 @@ module Dry
|
|
7
7
|
# @api public
|
8
8
|
class Enum
|
9
9
|
include Type
|
10
|
-
include Dry::Equalizer(:type, :mapping, inspect: false, immutable: true)
|
10
|
+
include ::Dry::Equalizer(:type, :mapping, inspect: false, immutable: true)
|
11
11
|
include Decorator
|
12
12
|
include Builder
|
13
13
|
|
@@ -36,27 +36,21 @@ module Dry
|
|
36
36
|
# @return [Object]
|
37
37
|
#
|
38
38
|
# @api private
|
39
|
-
def call_unsafe(input)
|
40
|
-
type.call_unsafe(map_value(input))
|
41
|
-
end
|
39
|
+
def call_unsafe(input) = type.call_unsafe(map_value(input))
|
42
40
|
|
43
41
|
# @return [Object]
|
44
42
|
#
|
45
43
|
# @api private
|
46
|
-
def call_safe(input, &
|
47
|
-
type.call_safe(map_value(input), &block)
|
48
|
-
end
|
44
|
+
def call_safe(input, &) = type.call_safe(map_value(input), &)
|
49
45
|
|
50
46
|
# @see Dry::Types::Constrained#try
|
51
47
|
#
|
52
48
|
# @api public
|
53
|
-
def try(input)
|
54
|
-
super(map_value(input))
|
55
|
-
end
|
49
|
+
def try(input) = super(map_value(input))
|
56
50
|
|
57
51
|
# @api private
|
58
52
|
def default(*)
|
59
|
-
raise ".enum(*values).default(value) is not supported. Call "\
|
53
|
+
raise ".enum(*values).default(value) is not supported. Call " \
|
60
54
|
".default(value).enum(*values) instead"
|
61
55
|
end
|
62
56
|
|
@@ -73,11 +67,37 @@ module Dry
|
|
73
67
|
# @return [String]
|
74
68
|
#
|
75
69
|
# @api public
|
76
|
-
def to_s
|
77
|
-
|
70
|
+
def to_s = PRINTER.(self)
|
71
|
+
|
72
|
+
# Iterate over each enum value
|
73
|
+
#
|
74
|
+
# @return [Array, Enumerator]
|
75
|
+
#
|
76
|
+
# @api public
|
77
|
+
def each_value(&)
|
78
|
+
values.each(&)
|
78
79
|
end
|
80
|
+
|
79
81
|
alias_method :inspect, :to_s
|
80
82
|
|
83
|
+
# @return [String]
|
84
|
+
#
|
85
|
+
# @api public
|
86
|
+
def name = "#{super}(#{joined_values})"
|
87
|
+
|
88
|
+
# @return [String]
|
89
|
+
#
|
90
|
+
# @api private
|
91
|
+
def joined_values
|
92
|
+
mapping.keys.map { |value|
|
93
|
+
if value.is_a?(::String)
|
94
|
+
value
|
95
|
+
else
|
96
|
+
value.inspect
|
97
|
+
end
|
98
|
+
}.join("|")
|
99
|
+
end
|
100
|
+
|
81
101
|
private
|
82
102
|
|
83
103
|
# Maps a value
|
data/lib/dry/types/errors.rb
CHANGED
@@ -56,14 +56,10 @@ module Dry
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# @return string
|
59
|
-
def message
|
60
|
-
errors.map(&:message).join(", ")
|
61
|
-
end
|
59
|
+
def message = errors.map(&:message).join(", ")
|
62
60
|
|
63
61
|
# @return [Array]
|
64
|
-
def meta
|
65
|
-
errors.map(&:meta)
|
66
|
-
end
|
62
|
+
def meta = errors.map(&:meta)
|
67
63
|
end
|
68
64
|
|
69
65
|
class SchemaError < CoercionError
|
@@ -80,7 +76,7 @@ module Dry
|
|
80
76
|
@key = key
|
81
77
|
@value = value
|
82
78
|
super(
|
83
|
-
"#{value.inspect} (#{value.class}) has invalid type "\
|
79
|
+
"#{value.inspect} (#{value.class}) has invalid type " \
|
84
80
|
"for :#{key} violates constraints (#{result} failed)"
|
85
81
|
)
|
86
82
|
end
|
@@ -125,7 +121,7 @@ module Dry
|
|
125
121
|
@result = result
|
126
122
|
@input = input
|
127
123
|
|
128
|
-
if result.is_a?(String)
|
124
|
+
if result.is_a?(::String)
|
129
125
|
super(result)
|
130
126
|
else
|
131
127
|
super(to_s)
|
@@ -70,9 +70,7 @@ module Dry
|
|
70
70
|
# @return [true]
|
71
71
|
#
|
72
72
|
# @api public
|
73
|
-
def default?
|
74
|
-
true
|
75
|
-
end
|
73
|
+
def default? = true
|
76
74
|
|
77
75
|
# @param [Object] value
|
78
76
|
#
|
@@ -83,7 +81,7 @@ module Dry
|
|
83
81
|
# @api public
|
84
82
|
def default(value)
|
85
83
|
if value.nil?
|
86
|
-
raise ArgumentError, "nil cannot be used as a default of a maybe type"
|
84
|
+
raise ::ArgumentError, "nil cannot be used as a default of a maybe type"
|
87
85
|
else
|
88
86
|
super
|
89
87
|
end
|
@@ -96,17 +94,13 @@ module Dry
|
|
96
94
|
# @return [Maybe]
|
97
95
|
#
|
98
96
|
# @api public
|
99
|
-
def maybe
|
100
|
-
Maybe.new(Types["nil"] | self)
|
101
|
-
end
|
97
|
+
def maybe = Maybe.new(Types["nil"] | self)
|
102
98
|
end
|
103
99
|
|
104
100
|
# @api private
|
105
101
|
class Schema::Key # rubocop:disable Style/ClassAndModuleChildren
|
106
102
|
# @api private
|
107
|
-
def maybe
|
108
|
-
__new__(type.maybe)
|
109
|
-
end
|
103
|
+
def maybe = __new__(type.maybe)
|
110
104
|
end
|
111
105
|
|
112
106
|
# @api private
|
@@ -12,8 +12,8 @@ module Dry
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# @api private
|
15
|
-
def self.register(function = Dry::Core::Constants::Undefined, &block)
|
16
|
-
fn = Dry::Core::Constants::Undefined.default(function, block)
|
15
|
+
def self.register(function = ::Dry::Core::Constants::Undefined, &block)
|
16
|
+
fn = ::Dry::Core::Constants::Undefined.default(function, block)
|
17
17
|
fn_name = register_name(fn)
|
18
18
|
container.register(fn_name, fn) unless container.key?(fn_name)
|
19
19
|
fn_name
|
@@ -30,7 +30,7 @@ module Dry
|
|
30
30
|
|
31
31
|
# @api private
|
32
32
|
def self.register_name(function)
|
33
|
-
"fn_#{function.
|
33
|
+
"fn_#{function.__id__}"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -8,23 +8,17 @@ module Dry
|
|
8
8
|
class Hash < Nominal
|
9
9
|
class Constructor < ::Dry::Types::Constructor
|
10
10
|
# @api private
|
11
|
-
def constructor_type
|
12
|
-
::Dry::Types::Hash::Constructor
|
13
|
-
end
|
11
|
+
def constructor_type = ::Dry::Types::Hash::Constructor
|
14
12
|
|
15
13
|
# @return [Lax]
|
16
14
|
#
|
17
15
|
# @api public
|
18
|
-
def lax
|
19
|
-
type.lax.constructor(fn, meta: meta)
|
20
|
-
end
|
16
|
+
def lax = Lax.new(type.lax.constructor(fn, meta: meta))
|
21
17
|
|
22
18
|
# @see Dry::Types::Array#of
|
23
19
|
#
|
24
20
|
# @api public
|
25
|
-
def schema(...)
|
26
|
-
type.schema(...).constructor(fn, meta: meta)
|
27
|
-
end
|
21
|
+
def schema(...) = type.schema(...).constructor(fn, meta: meta)
|
28
22
|
end
|
29
23
|
end
|
30
24
|
end
|
data/lib/dry/types/hash.rb
CHANGED
@@ -48,7 +48,7 @@ module Dry
|
|
48
48
|
|
49
49
|
# @api private
|
50
50
|
def weak(*)
|
51
|
-
raise "Support for old hash schemas was removed, please refer to the CHANGELOG "\
|
51
|
+
raise "Support for old hash schemas was removed, please refer to the CHANGELOG " \
|
52
52
|
"on how to proceed with the new API https://github.com/dry-rb/dry-types/blob/main/CHANGELOG.md"
|
53
53
|
end
|
54
54
|
alias_method :permissive, :weak
|
@@ -67,9 +67,9 @@ module Dry
|
|
67
67
|
def with_type_transform(proc = nil, &block)
|
68
68
|
fn = proc || block
|
69
69
|
|
70
|
-
raise ArgumentError, "a block or callable argument is required" if fn.nil?
|
70
|
+
raise ::ArgumentError, "a block or callable argument is required" if fn.nil?
|
71
71
|
|
72
|
-
handle = Dry::Types::FnContainer.register(fn)
|
72
|
+
handle = ::Dry::Types::FnContainer.register(fn)
|
73
73
|
with(type_transform_fn: handle)
|
74
74
|
end
|
75
75
|
|
@@ -93,7 +93,9 @@ module Dry
|
|
93
93
|
#
|
94
94
|
# @api public
|
95
95
|
def to_ast(meta: true)
|
96
|
-
[:hash,
|
96
|
+
[:hash,
|
97
|
+
[options.slice(:type_transform_fn),
|
98
|
+
meta ? self.meta : EMPTY_HASH]]
|
97
99
|
end
|
98
100
|
|
99
101
|
private
|
@@ -101,7 +103,7 @@ module Dry
|
|
101
103
|
# @api private
|
102
104
|
def build_keys(type_map)
|
103
105
|
type_fn = options.fetch(:type_transform_fn, Schema::NO_TRANSFORM)
|
104
|
-
type_transform = Dry::Types::FnContainer[type_fn]
|
106
|
+
type_transform = ::Dry::Types::FnContainer[type_fn]
|
105
107
|
|
106
108
|
type_map.map do |map_key, type|
|
107
109
|
name, options = key_name(map_key)
|
@@ -115,7 +117,7 @@ module Dry
|
|
115
117
|
case type
|
116
118
|
when Type then type
|
117
119
|
when ::Class, ::String then Types[type]
|
118
|
-
else type
|
120
|
+
else type # rubocop:disable Lint/DuplicateBranch
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
@@ -8,9 +8,7 @@ module Dry
|
|
8
8
|
class Implication
|
9
9
|
include Composition
|
10
10
|
|
11
|
-
def self.operator
|
12
|
-
:>
|
13
|
-
end
|
11
|
+
def self.operator = :>
|
14
12
|
|
15
13
|
# @param [Object] input
|
16
14
|
#
|
@@ -30,9 +28,9 @@ module Dry
|
|
30
28
|
# @return [Object]
|
31
29
|
#
|
32
30
|
# @api private
|
33
|
-
def call_safe(input, &
|
31
|
+
def call_safe(input, &)
|
34
32
|
if left.try(input).success?
|
35
|
-
right.call_safe(input, &
|
33
|
+
right.call_safe(input, &)
|
36
34
|
else
|
37
35
|
input
|
38
36
|
end
|
data/lib/dry/types/inflector.rb
CHANGED
@@ -12,9 +12,7 @@ module Dry
|
|
12
12
|
class Intersection
|
13
13
|
include Composition
|
14
14
|
|
15
|
-
def self.operator
|
16
|
-
:&
|
17
|
-
end
|
15
|
+
def self.operator = :&
|
18
16
|
|
19
17
|
# @param [Object] input
|
20
18
|
#
|
@@ -30,9 +28,7 @@ module Dry
|
|
30
28
|
# @return [Object]
|
31
29
|
#
|
32
30
|
# @api private
|
33
|
-
def call_safe(input, &
|
34
|
-
try_sides(input, &block).input
|
35
|
-
end
|
31
|
+
def call_safe(input, &) = try_sides(input, &).input
|
36
32
|
|
37
33
|
# @param [Object] input
|
38
34
|
#
|
@@ -94,9 +90,7 @@ module Dry
|
|
94
90
|
def merge_results(left_result, right_result)
|
95
91
|
case left_result
|
96
92
|
when ::Array
|
97
|
-
left_result
|
98
|
-
.zip(right_result)
|
99
|
-
.map { |lhs, rhs| merge_results(lhs, rhs) }
|
93
|
+
left_result.zip(right_result).map { merge_results(_1, _2) }
|
100
94
|
when ::Hash
|
101
95
|
left_result.merge(right_result)
|
102
96
|
else
|
data/lib/dry/types/lax.rb
CHANGED
@@ -10,7 +10,7 @@ module Dry
|
|
10
10
|
include Decorator
|
11
11
|
include Builder
|
12
12
|
include Printable
|
13
|
-
include Dry::Equalizer(:type, inspect: false, immutable: true)
|
13
|
+
include ::Dry::Equalizer(:type, inspect: false, immutable: true)
|
14
14
|
|
15
15
|
undef :options, :constructor, :<<, :>>, :prepend, :append
|
16
16
|
|
@@ -35,23 +35,17 @@ module Dry
|
|
35
35
|
# @return [Result,Logic::Result]
|
36
36
|
#
|
37
37
|
# @api public
|
38
|
-
def try(input, &
|
39
|
-
type.try(input, &block)
|
40
|
-
end
|
38
|
+
def try(input, &) = type.try(input, &)
|
41
39
|
|
42
40
|
# @see Nominal#to_ast
|
43
41
|
#
|
44
42
|
# @api public
|
45
|
-
def to_ast(meta: true)
|
46
|
-
[:lax, type.to_ast(meta: meta)]
|
47
|
-
end
|
43
|
+
def to_ast(meta: true) = [:lax, type.to_ast(meta: meta)]
|
48
44
|
|
49
45
|
# @return [Lax]
|
50
46
|
#
|
51
47
|
# @api public
|
52
|
-
def lax
|
53
|
-
self
|
54
|
-
end
|
48
|
+
def lax = self
|
55
49
|
|
56
50
|
private
|
57
51
|
|
data/lib/dry/types/map.rb
CHANGED
@@ -24,29 +24,23 @@ module Dry
|
|
24
24
|
# @api public
|
25
25
|
class Map < Nominal
|
26
26
|
def initialize(primitive, key_type: Types["any"], value_type: Types["any"], meta: EMPTY_HASH)
|
27
|
-
super
|
27
|
+
super
|
28
28
|
end
|
29
29
|
|
30
30
|
# @return [Type]
|
31
31
|
#
|
32
32
|
# @api public
|
33
|
-
def key_type
|
34
|
-
options[:key_type]
|
35
|
-
end
|
33
|
+
def key_type = options[:key_type]
|
36
34
|
|
37
35
|
# @return [Type]
|
38
36
|
#
|
39
37
|
# @api public
|
40
|
-
def value_type
|
41
|
-
options[:value_type]
|
42
|
-
end
|
38
|
+
def value_type = options[:value_type]
|
43
39
|
|
44
40
|
# @return [String]
|
45
41
|
#
|
46
42
|
# @api public
|
47
|
-
def name
|
48
|
-
"Map"
|
49
|
-
end
|
43
|
+
def name = "Map"
|
50
44
|
|
51
45
|
# @param [Hash] hash
|
52
46
|
#
|
@@ -64,9 +58,7 @@ module Dry
|
|
64
58
|
# @return [Hash]
|
65
59
|
#
|
66
60
|
# @api private
|
67
|
-
def call_safe(hash)
|
68
|
-
try(hash) { return yield }.input
|
69
|
-
end
|
61
|
+
def call_safe(hash) = try(hash) { return yield }.input
|
70
62
|
|
71
63
|
# @param [Hash] hash
|
72
64
|
#
|
@@ -95,48 +87,48 @@ module Dry
|
|
95
87
|
# @return [Boolean]
|
96
88
|
#
|
97
89
|
# @api public
|
98
|
-
def constrained?
|
99
|
-
value_type.constrained?
|
100
|
-
end
|
90
|
+
def constrained? = value_type.constrained?
|
101
91
|
|
102
92
|
private
|
103
93
|
|
104
94
|
# @api private
|
105
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
106
95
|
# rubocop:disable Metrics/AbcSize
|
107
96
|
def coerce(input)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
97
|
+
assert_primitive(input) do
|
98
|
+
output = {}
|
99
|
+
failures = []
|
100
|
+
|
101
|
+
input.each do |k, v|
|
102
|
+
res_k = key_type.try(k)
|
103
|
+
res_v = value_type.try(v)
|
104
|
+
|
105
|
+
if res_k.failure?
|
106
|
+
failures << res_k.error
|
107
|
+
elsif output.key?(res_k.input)
|
108
|
+
failures << CoercionError.new("duplicate coerced hash key #{res_k.input.inspect}")
|
109
|
+
elsif res_v.failure?
|
110
|
+
failures << res_v.error
|
111
|
+
else
|
112
|
+
output[res_k.input] = res_v.input
|
113
|
+
end
|
114
|
+
end
|
120
115
|
|
121
|
-
if
|
122
|
-
|
123
|
-
elsif output.key?(res_k.input)
|
124
|
-
failures << CoercionError.new("duplicate coerced hash key #{res_k.input.inspect}")
|
125
|
-
elsif res_v.failure?
|
126
|
-
failures << res_v.error
|
116
|
+
if failures.empty?
|
117
|
+
success(output)
|
127
118
|
else
|
128
|
-
|
119
|
+
failure(input, MultipleError.new(failures))
|
129
120
|
end
|
130
121
|
end
|
122
|
+
end
|
123
|
+
# rubocop:enable Metrics/AbcSize
|
131
124
|
|
132
|
-
|
133
|
-
|
125
|
+
def assert_primitive(input)
|
126
|
+
if primitive?(input)
|
127
|
+
yield
|
134
128
|
else
|
135
|
-
failure(input,
|
129
|
+
failure(input, CoercionError.new("#{input.inspect} must be an instance of #{primitive}"))
|
136
130
|
end
|
137
131
|
end
|
138
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
139
|
-
# rubocop:enable Metrics/AbcSize
|
140
132
|
end
|
141
133
|
end
|
142
134
|
end
|
data/lib/dry/types/meta.rb
CHANGED
@@ -16,9 +16,7 @@ module Dry
|
|
16
16
|
# @return [Type]
|
17
17
|
#
|
18
18
|
# @api public
|
19
|
-
def with(**options)
|
20
|
-
super(meta: @meta, **options)
|
21
|
-
end
|
19
|
+
def with(**options) = super(meta: @meta, **options)
|
22
20
|
|
23
21
|
# @overload meta
|
24
22
|
# @return [Hash] metadata associated with type
|
@@ -43,9 +41,7 @@ module Dry
|
|
43
41
|
# @return [Dry::Types::Type]
|
44
42
|
#
|
45
43
|
# @api public
|
46
|
-
def pristine
|
47
|
-
with(meta: EMPTY_HASH)
|
48
|
-
end
|
44
|
+
def pristine = with(meta: EMPTY_HASH)
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
data/lib/dry/types/module.rb
CHANGED
@@ -38,7 +38,6 @@ module Dry
|
|
38
38
|
|
39
39
|
# @api private
|
40
40
|
# rubocop:disable Metrics/AbcSize
|
41
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
42
41
|
# rubocop:disable Metrics/PerceivedComplexity
|
43
42
|
def type_constants(*namespaces, default: Undefined, **aliases)
|
44
43
|
if namespaces.empty? && aliases.empty? && Undefined.equal?(default)
|
@@ -52,7 +51,7 @@ module Dry
|
|
52
51
|
tree = registry_tree
|
53
52
|
|
54
53
|
if namespaces.empty? && aliases.empty?
|
55
|
-
modules = tree.select {
|
54
|
+
modules = tree.select { _2.is_a?(::Hash) }.map(&:first)
|
56
55
|
else
|
57
56
|
modules = (namespaces + aliases.keys).map { |n|
|
58
57
|
Types::Inflector.camelize(n).to_sym
|
@@ -69,7 +68,6 @@ module Dry
|
|
69
68
|
end
|
70
69
|
end
|
71
70
|
# rubocop:enable Metrics/AbcSize
|
72
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
73
71
|
# rubocop:enable Metrics/PerceivedComplexity
|
74
72
|
|
75
73
|
# @api private
|
@@ -101,8 +99,8 @@ module Dry
|
|
101
99
|
unknown = (referenced.uniq - known).first
|
102
100
|
|
103
101
|
if unknown
|
104
|
-
raise ArgumentError,
|
105
|
-
"#{unknown.inspect} is not a known type namespace. "\
|
102
|
+
raise ::ArgumentError,
|
103
|
+
"#{unknown.inspect} is not a known type namespace. " \
|
106
104
|
"Supported options are #{known.map(&:inspect).join(", ")}"
|
107
105
|
end
|
108
106
|
end
|
data/lib/dry/types/nominal.rb
CHANGED
@@ -48,48 +48,36 @@ module Dry
|
|
48
48
|
# @return [String]
|
49
49
|
#
|
50
50
|
# @api public
|
51
|
-
def name
|
52
|
-
primitive.name
|
53
|
-
end
|
51
|
+
def name = primitive.name
|
54
52
|
|
55
53
|
# @return [false]
|
56
54
|
#
|
57
55
|
# @api public
|
58
|
-
def default?
|
59
|
-
false
|
60
|
-
end
|
56
|
+
def default? = false
|
61
57
|
|
62
58
|
# @return [false]
|
63
59
|
#
|
64
60
|
# @api public
|
65
|
-
def constrained?
|
66
|
-
false
|
67
|
-
end
|
61
|
+
def constrained? = false
|
68
62
|
|
69
63
|
# @return [false]
|
70
64
|
#
|
71
65
|
# @api public
|
72
|
-
def optional?
|
73
|
-
false
|
74
|
-
end
|
66
|
+
def optional? = false
|
75
67
|
|
76
68
|
# @param [BasicObject] input
|
77
69
|
#
|
78
70
|
# @return [BasicObject]
|
79
71
|
#
|
80
72
|
# @api private
|
81
|
-
def call_unsafe(input)
|
82
|
-
input
|
83
|
-
end
|
73
|
+
def call_unsafe(input) = input
|
84
74
|
|
85
75
|
# @param [BasicObject] input
|
86
76
|
#
|
87
77
|
# @return [BasicObject]
|
88
78
|
#
|
89
79
|
# @api private
|
90
|
-
def call_safe(input)
|
91
|
-
input
|
92
|
-
end
|
80
|
+
def call_safe(input) = input
|
93
81
|
|
94
82
|
# @param [Object] input
|
95
83
|
#
|
@@ -100,18 +88,14 @@ module Dry
|
|
100
88
|
# @return [nil] otherwise
|
101
89
|
#
|
102
90
|
# @api public
|
103
|
-
def try(input)
|
104
|
-
success(input)
|
105
|
-
end
|
91
|
+
def try(input) = success(input)
|
106
92
|
|
107
93
|
# @param (see Dry::Types::Success#initialize)
|
108
94
|
#
|
109
95
|
# @return [Result::Success]
|
110
96
|
#
|
111
97
|
# @api public
|
112
|
-
def success(input)
|
113
|
-
Result::Success.new(input)
|
114
|
-
end
|
98
|
+
def success(input) = Result::Success.new(input)
|
115
99
|
|
116
100
|
# @param (see Failure#initialize)
|
117
101
|
#
|
@@ -119,7 +103,7 @@ module Dry
|
|
119
103
|
#
|
120
104
|
# @api public
|
121
105
|
def failure(input, error)
|
122
|
-
raise ArgumentError, "error must be a CoercionError" unless error.is_a?(CoercionError)
|
106
|
+
raise ::ArgumentError, "error must be a CoercionError" unless error.is_a?(CoercionError)
|
123
107
|
|
124
108
|
Result::Failure.new(input, error)
|
125
109
|
end
|
@@ -131,12 +115,10 @@ module Dry
|
|
131
115
|
# @return [Boolean]
|
132
116
|
#
|
133
117
|
# @api public
|
134
|
-
def primitive?(value)
|
135
|
-
value.is_a?(primitive)
|
136
|
-
end
|
118
|
+
def primitive?(value) = value.is_a?(primitive)
|
137
119
|
|
138
120
|
# @api private
|
139
|
-
def coerce(input, &
|
121
|
+
def coerce(input, &)
|
140
122
|
if primitive?(input)
|
141
123
|
input
|
142
124
|
elsif block_given?
|
@@ -178,18 +160,14 @@ module Dry
|
|
178
160
|
# @return [Nominal]
|
179
161
|
#
|
180
162
|
# @api public
|
181
|
-
def lax
|
182
|
-
self
|
183
|
-
end
|
163
|
+
def lax = self
|
184
164
|
|
185
165
|
# Wrap the type with a proc
|
186
166
|
#
|
187
167
|
# @return [Proc]
|
188
168
|
#
|
189
169
|
# @api public
|
190
|
-
def to_proc
|
191
|
-
ALWAYS
|
192
|
-
end
|
170
|
+
def to_proc = ALWAYS
|
193
171
|
end
|
194
172
|
|
195
173
|
extend ::Dry::Core::Deprecations[:"dry-types"]
|
@@ -137,7 +137,7 @@ module Dry
|
|
137
137
|
left = visit(left_node)
|
138
138
|
right = visit(right_node)
|
139
139
|
|
140
|
-
if left.eql?(NIL)
|
140
|
+
if left.eql?(NIL) # rubocop:disable Lint/DeprecatedConstants
|
141
141
|
right
|
142
142
|
else
|
143
143
|
[[left, right]]
|
@@ -157,9 +157,7 @@ module Dry
|
|
157
157
|
end
|
158
158
|
|
159
159
|
# @api private
|
160
|
-
def visit_any(_)
|
161
|
-
EMPTY_ARRAY
|
162
|
-
end
|
160
|
+
def visit_any(_) = EMPTY_ARRAY
|
163
161
|
|
164
162
|
# @api private
|
165
163
|
def visit_and(node)
|
@@ -185,6 +183,11 @@ module Dry
|
|
185
183
|
end
|
186
184
|
end
|
187
185
|
|
186
|
+
# @api private
|
187
|
+
def visit_map(_node)
|
188
|
+
raise ::NotImplementedError, "map types are not supported yet"
|
189
|
+
end
|
190
|
+
|
188
191
|
private
|
189
192
|
|
190
193
|
# @api private
|