Module: Tapioca::Compilers::Sorbet

Extended by:
T::Sig
Defined in:
lib/tapioca/compilers/sorbet.rb

Constant Summary collapse

SORBET_GEM_SPEC =
T.let(
  Gem::Specification.find_by_name("sorbet-static"),
  Gem::Specification
)
SORBET =
T.let(
  Pathname.new(SORBET_GEM_SPEC.full_gem_path) / "libexec" / "sorbet",
  Pathname
)
EXE_PATH_ENV_VAR =
"TAPIOCA_SORBET_EXE"
FEATURE_REQUIREMENTS =
T.let({
}.freeze, T::Hash[Symbol, Gem::Requirement])

Class Method Summary collapse

Class Method Details

.run(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/tapioca/compilers/sorbet.rb', line 27

def run(*args)
  IO.popen(
    [
      sorbet_path,
      "--quiet",
      *args,
    ].join(" "),
    err: "/dev/null"
  ).read
end

.sorbet_pathObject



39
40
41
42
43
# File 'lib/tapioca/compilers/sorbet.rb', line 39

def sorbet_path
  sorbet_path = ENV.fetch(EXE_PATH_ENV_VAR, SORBET)
  sorbet_path = SORBET if sorbet_path.empty?
  sorbet_path.to_s.shellescape
end

.supports?(feature, version: nil) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
# File 'lib/tapioca/compilers/sorbet.rb', line 46

def supports?(feature, version: nil)
  version = SORBET_GEM_SPEC.version unless version
  requirement = FEATURE_REQUIREMENTS[feature]

  raise "Invalid Sorbet feature #{feature}" unless requirement

  requirement.satisfied_by?(version)
end