sorbet-coerce 0.4.0 → 0.5.0

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: 7503ed812a03fc5478701f1821be08195b10945d700dd27cda21088aa2e01f55
4
- data.tar.gz: 6fd2a30012fad3af9f5fceee3de2a60c03bc7fb3f7fccdf42223b669c0e8c409
3
+ metadata.gz: 459ea1a3f906360f8a0e0d33969f49110476a1aa8d1772a1adc4dc1fc704140c
4
+ data.tar.gz: 7e2bf805fcb1d89de859312576d7e9e4eb782d03e4e7ff5929205c0fb676e377
5
5
  SHA512:
6
- metadata.gz: ebbeb777352a39fe67575ee44c12ccb4ad1433ff7504bd76a9f9b86d91aef09a6e120496763254f433af783e2ab6dfec17b7822651db1bf563f9b7f223e8149c
7
- data.tar.gz: 7d536c441a095d32af634b7ad362750e9c6d4f95789cf9cfdeb3d77aa0a90485ca4622517d3138cf7815c9eadc0e282ef7e75711b5fde27d4bfcca75b561dba8
6
+ metadata.gz: c75dfa39c75773bd161fc67f2ee145192bc6431f58db621a39eadd2c02948d39a117f3d1a5c8ad277338cf1ab0342a6f4153f20326bd379e28e8a734ca1d190c
7
+ data.tar.gz: d9c87f91c2586aac705089fe519d6c58e28854fe8cf87019468f46ad4421e8166d5f042c6f512c983d25b120e4b31f699f755706694a47a29c91b2d38c1a5a78
@@ -130,6 +130,8 @@ class TypeCoerce::Converter
130
130
  safe_type_rule = SafeType::Boolean.strict
131
131
  elsif value.is_a?(type)
132
132
  return value
133
+ elsif type == BigDecimal
134
+ return BigDecimal(value)
133
135
  elsif PRIMITIVE_TYPES.include?(type)
134
136
  safe_type_rule = SafeType.const_get(type.name).strict
135
137
  else
data/spec/coerce_spec.rb CHANGED
@@ -19,6 +19,7 @@ describe TypeCoerce do
19
19
  class Param < T::Struct
20
20
  const :id, Integer
21
21
  const :role, String, default: 'wizard'
22
+ const :price, BigDecimal
22
23
  const :info, ParamInfo
23
24
  const :opt, T.nilable(ParamInfo2)
24
25
  end
@@ -65,6 +66,7 @@ describe TypeCoerce do
65
66
  let!(:param) {
66
67
  TypeCoerce[Param].new.from({
67
68
  id: 1,
69
+ price: BigDecimal('98.76'),
68
70
  info: {
69
71
  name: 'mango',
70
72
  lvl: 100,
@@ -81,6 +83,7 @@ describe TypeCoerce do
81
83
  let!(:param2) {
82
84
  TypeCoerce[Param].new.from({
83
85
  id: '2',
86
+ price: '98.76',
84
87
  info: {
85
88
  name: 'honeydew',
86
89
  lvl: '5',
@@ -97,6 +100,7 @@ describe TypeCoerce do
97
100
  it 'reveals the right type' do
98
101
  T.assert_type!(param, Param)
99
102
  T.assert_type!(param.id, Integer)
103
+ T.assert_type!(param.price, BigDecimal)
100
104
  T.assert_type!(param.info, ParamInfo)
101
105
  T.assert_type!(param.info.name,String)
102
106
  T.assert_type!(param.info.lvl, Integer)
@@ -106,6 +110,7 @@ describe TypeCoerce do
106
110
  it 'coerces correctly' do
107
111
  expect(param.id).to eql 1
108
112
  expect(param.role).to eql 'wizard'
113
+ expect(param.price).to eql BigDecimal('98.76')
109
114
  expect(param.info.lvl).to eql 100
110
115
  expect(param.info.name).to eql 'mango'
111
116
  expect(param.info.skill_ids).to eql [123, 456]
@@ -113,6 +118,7 @@ describe TypeCoerce do
113
118
  expect(TypeCoerce[Param].new.from(param)).to eq(param)
114
119
 
115
120
  expect(param2.id).to eql 2
121
+ expect(param2.price).to eql BigDecimal('98.76')
116
122
  expect(param2.info.name).to eql 'honeydew'
117
123
  expect(param2.info.lvl).to eql 5
118
124
  expect(param2.info.skill_ids).to eql []
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chan Zuckerberg Initiative