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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a6067fb52161543309158003029c02c354f0c88d6dada780973141b4c7f3ca5
4
- data.tar.gz: 15e371a34bdbb450ffa5a24f6f235d4f67f7b6964c1819a81286d60f687f2d66
3
+ metadata.gz: 61b6f639daa4889060a9540e4fd31f7fbfe19529dac7246a91dc4ea9355b9d70
4
+ data.tar.gz: 7d0ec3164d26cbf16bc45e94820f02142197191e3cc7ae4db7e8c21db351a0f3
5
5
  SHA512:
6
- metadata.gz: f0000b0124391cb0432486aaa4193442bb5adfd3ff67552bb6671a38ea4709f9c81b850355b838e00f6dda72f5d207f117b694dee1f78eb9f4d2805af7cad55d
7
- data.tar.gz: 1ac80f3aad685c57123d4acd67178385a0068190676c4446d4bc6c99945e8313ea67b09e2a40958fc7e08778d8811a969e0467b46ed5071fc80d5aafa429de75
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
@@ -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
- T.assert_type!(TypeCoerce[CustomType].new.from(a: 1), CustomType)
167
- expect(TypeCoerce[CustomType].new.from(1).a).to be 1
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-coerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chan Zuckerberg Initiative