sorbet-coerce 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sorbet-coerce/converter.rb +4 -0
- data/spec/coerce_spec.rb +5 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61b6f639daa4889060a9540e4fd31f7fbfe19529dac7246a91dc4ea9355b9d70
|
4
|
+
data.tar.gz: 7d0ec3164d26cbf16bc45e94820f02142197191e3cc7ae4db7e8c21db351a0f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2ce360c7fd4474d57e3fc5b1115d3711ae41b177a60dcc2f07239f602aab45ab2a6a0ba429df9d7d2edc7df4689cac4f76d3b363ebd055b5b9a53be551e6e83
|
7
|
+
data.tar.gz: 3a3af86be35e961882e11a326e4609376eb3a2fd6a30658be044559fad9b56feabeeae226b91fb85f6b515304a9f982d40e1aaebc9b3a462c076031c1418dfd4
|
@@ -75,9 +75,13 @@ module TypeCoerce::Private
|
|
75
75
|
type.is_a?(T::Private::Types::TypeAlias)
|
76
76
|
_convert(value, type.aliased_type, raise_coercion_error)
|
77
77
|
elsif type.respond_to?(:<) && type < T::Struct
|
78
|
+
return value if value.is_a?(type)
|
79
|
+
|
78
80
|
args = _build_args(value, type, raise_coercion_error)
|
79
81
|
type.new(args)
|
80
82
|
else
|
83
|
+
return value if value.is_a?(type)
|
84
|
+
|
81
85
|
_convert_simple(value, type, raise_coercion_error)
|
82
86
|
end
|
83
87
|
end
|
data/spec/coerce_spec.rb
CHANGED
@@ -99,6 +99,7 @@ describe TypeCoerce do
|
|
99
99
|
expect(param.info.name).to eql 'mango'
|
100
100
|
expect(param.info.skill_ids).to eql [123, 456]
|
101
101
|
expect(param.opt.notes).to eql []
|
102
|
+
expect(TypeCoerce[Param].new.from(param)).to eq(param)
|
102
103
|
|
103
104
|
expect(param2.id).to eql 2
|
104
105
|
expect(param2.info.name).to eql 'honeydew'
|
@@ -163,8 +164,10 @@ describe TypeCoerce do
|
|
163
164
|
|
164
165
|
context 'when given custom types' do
|
165
166
|
it 'coerces correctly' do
|
166
|
-
|
167
|
-
|
167
|
+
obj = TypeCoerce[CustomType].new.from(1)
|
168
|
+
T.assert_type!(obj, CustomType)
|
169
|
+
expect(obj.a).to be 1
|
170
|
+
expect(TypeCoerce[CustomType].new.from(obj)).to be obj
|
168
171
|
|
169
172
|
expect{TypeCoerce[UnsupportedCustomType].new.from(1)}.to raise_error(ArgumentError)
|
170
173
|
# CustomType2.new(anything) returns Integer 1; 1.is_a?(CustomType2) == false
|