Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using Sorbet #122

Open
movermeyer opened this issue Apr 18, 2022 · 1 comment
Open

Consider using Sorbet #122

movermeyer opened this issue Apr 18, 2022 · 1 comment

Comments

@movermeyer
Copy link
Collaborator

Sorbet is a gradual typing system.

Consider typing ruby-cldr using Sorbet to help catch typing bugs?

@movermeyer
Copy link
Collaborator Author

movermeyer commented Apr 21, 2022

Aside: There was a suggestion that if we wanted to tie ourselves to Sorbet, that we could use it's Enum to implement DraftStatus in a slightly different way:

# typed: strict
class Status < T::Enum
  extend T::Sig

  enums do
    Unconfirmed = new
    Provisional = new
    Contributed = new
    Approved = new
  end

  sig { returns(Integer) }
  def to_i
    case self
    when Unconfirmed then 1
    when Provisional then 2
    when Contributed then 3
    when Approved then 4
    else T.absurd(self)
    end
  end

  sig { params(other: Status).returns(Integer) }
  def <=>(other)
    to_i <=> other.to_i
  end

  sig { params(name: String).returns(Status) }
  def self.fetch(name)
    case name
    when 'unconfirmed' then Unconfirmed
    when 'provisional' then Provisional
    when 'contributed' then Contributed
    when 'approved' then Approved
    else
      raise ArgumentError, "invalid status: #{name}"
    end
  end
end

That way it can do some fun things like completeness checks on case statements.
(I'm not sure that it's worth the dependency though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant