Skip to content

Commit

Permalink
Release v0.1.3 (#17)
Browse files Browse the repository at this point in the history
- Fix the build for new sorbet version 0.4.4901
  - Handle type aliases (e.g. T::Boolean)
- Update the encrypted API token
  • Loading branch information
donaldong authored Oct 24, 2019
1 parent d17cf11 commit 3f37984
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ script:
deploy:
provider: rubygems
api_key:
secure: AVQi+tC5+HEoGgOKj/+/UeizOkwgVoB8zdPrd48/H9rx1KsAAmQ+2N9srOnrrEkm9I/bvHLOs0JpM96IiXFhztzrDefkaYQc1Zhu3tbWKZf6kuw0gabTMGhx3JsLoQiYRbJYea1qfrL0XlvQTxgkaa4zGJQaIBIZ97X7jlG5lVcys7JGjUFkozGJgS0t2HDffgDPLs3SiWR380Zvo4xcogw9tFHg5MuirZM/bXb9C/WhdDmKV9LbM8bTkJBjkZ0jbzKITtDJWSCXzdjRebLesTVN6F6cNWkwp2TumefgpQId4uGa5iUN8nXriqN890jjeZ3xHDq7xF0dRZgr8TyreocevCtNPCl+12c9ook0+mJn2GFTJL4W9BTuBGkBFekcQZ5MChWywcJ280iuPfX56Ilpt0wkCtWgB0k+k+eGTgEUv0iLykRFytNfiXr1oySG6mzxcUMf90IxfIKMydjFl8ZmAoTmZDfECtk59IW3PRwfHnNiNwmGMIGz9x9geO0wORWWnqdAwvHnQ7wMdScbSZ/VIPvpBdNe3rbhh4xAXXen+t1V0jvAlkBng9GLCwaRWuAsQG3fvRCbjWGxVmCLaQjUqIoJOtNVgeww+s5bXc8eVUtJ2UNRNnlN78lCWrRBhEfgRoyhVzl47vSZjhOE/2JlmQhpot9nwmMOz1h9wk8=
secure: ZORE7pdzmJOcPvQZBhHyxerEC6JvPOlUki8Vk3pED1XxV/QbS4Dc1Lcm71RX7Y+7eW7OUuLKDakfKKPveEFFvDQWx8CvyGvOlUJJlk7ZizQAnydwrLfDgPj/LufzPn5OV8UJ/P0dNgdGV+rCtXszRp1uPfGn87e7cQq2vILUyOPOxmUGXuoySr08NxfIN5cU/NNTVNCox3/INnDxQKMg1bLkyg8yhuPHO/CDGQl5yYXm/5Fxa4Un8sIM+HpTuEDIh60YHZPzxdEAL4zm6UyPTpGIA9xP0Yv4jegSzBvY2HIT9glRN48VkqxlMf/xu54yv/2legWlmOQak11udhl+a7vEHqzJ6zpytZMVPQsvYvkoduO1AFRVJDeeYU6nFA9swJunUDvYDVqWWsk/bJraM2HHJjd1a5EKKUTZXF9GVOynco075KHMySSarSwiE+e/fTYxANkJoJyoR6k+31LDnw3KK1SeDj+HgCdlGvcomGDb9z/XDpexuYtWe0/7ShDn3UwzI5h0uOhEK3ryzn74y0v9Zm2r6qbFB819AD4BujPu9WTnBQyNwJXEJ/e+AKF3M9A3rtzCVXbZcOgxxr/dp5Kae6B0HUY14+Hq7O9Y3m7aiSgDlAVXyj6aKeRZu1xYCjVDkYX5mQeFOOwGh2irZg0FQnyloJHOmTlxZRqLTd4=
gem: sorbet-coerce
on:
tags: true
Expand Down
5 changes: 4 additions & 1 deletion lib/private/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ def _convert(value, type)
else
_convert(value, type.types[nil_idx == 0 ? 1 : 0])
end
elsif Object.const_defined?('T::Private::Types::TypeAlias') &&
type.is_a?(T::Private::Types::TypeAlias)
_convert(value, type.aliased_type)
elsif type < T::Struct
args = _build_args(value, type.props)
begin
type.new(args)
rescue T::Props::InvalidValueError, ArgumentError
rescue
nil
end
else
Expand Down
11 changes: 9 additions & 2 deletions lib/sorbet-coerce.rbi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# typed: strong

# typed: true
module T
module Coerce
extend T::Sig
Expand All @@ -10,4 +9,12 @@ module T
sig { params(args: T.untyped).returns(Elem) }
def from(args); end
end

module Private
module Types
class TypeAlias
def aliased_type; end
end
end
end
end
2 changes: 1 addition & 1 deletion sorbet-coerce.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = %q{sorbet-coerce}
s.version = "0.1.2"
s.version = "0.1.3"
s.date = %q{2019-10-04}
s.summary = %q{A type coercion lib works with Sorbet's static type checker and type definitions; raises an error if the coercion fails.}
s.authors = ["Chan Zuckerberg Initiative"]
Expand Down
10 changes: 9 additions & 1 deletion spec/coerce_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: ignore
require 'sorbet-coerce'
require 'sorbet-runtime'

Expand Down Expand Up @@ -164,4 +164,12 @@ class Param2 < T::Struct
expect(infos.first.name).to eql 'b'
end
end

context 'when given a type alias' do
MyType = T.type_alias(T::Boolean)

it 'coerces correctly' do
expect(T::Coerce[MyType].new.from('false')).to be false
end
end
end

0 comments on commit 3f37984

Please sign in to comment.