Module: Tapioca::SorbetHelper

Extended by:
T::Sig
Included in:
Commands::CheckShims, Commands::Dsl, Commands::Gem, Commands::Todo, Dsl::Compilers::ActiveRecordRelations, RBIHelper, RBIHelper, Tapioca::Static::SymbolLoader
Defined in:
lib/tapioca/helpers/sorbet_helper.rb

Constant Summary collapse

SORBET_GEM_SPEC =
T.let(
  ::Gem::Specification.find_by_name("sorbet-static"),
  ::Gem::Specification,
)
SORBET_BIN =
T.let(
  Pathname.new(SORBET_GEM_SPEC.full_gem_path) / "libexec" / "sorbet",
  Pathname,
)
SORBET_EXE_PATH_ENV_VAR =
"TAPIOCA_SORBET_EXE"
SORBET_PAYLOAD_URL =
"https://github.com/sorbet/sorbet/tree/master/rbi"
SPOOM_CONTEXT =
T.let(Spoom::Context.new("."), Spoom::Context)
FEATURE_REQUIREMENTS =
T.let(
  {
    # feature_name: ::Gem::Requirement.new(">= ___"), # https://github.com/sorbet/sorbet/pull/___
    non_generic_weak_map: ::Gem::Requirement.new(">= 0.5.10587"), # https://github.com/sorbet/sorbet/pull/6610
    generic_class: ::Gem::Requirement.new(">= 0.5.10820"), # https://github.com/sorbet/sorbet/pull/6781
  }.freeze,
  T::Hash[Symbol, ::Gem::Requirement],
)

Instance Method Summary collapse

Instance Method Details

#sorbet(*sorbet_args) ⇒ Object



34
35
36
# File 'lib/tapioca/helpers/sorbet_helper.rb', line 34

def sorbet(*sorbet_args)
  SPOOM_CONTEXT.srb(sorbet_args.join(" "), sorbet_bin: sorbet_path)
end

#sorbet_pathObject



39
40
41
42
43
# File 'lib/tapioca/helpers/sorbet_helper.rb', line 39

def sorbet_path
  sorbet_path = ENV.fetch(SORBET_EXE_PATH_ENV_VAR, SORBET_BIN)
  sorbet_path = SORBET_BIN if sorbet_path.empty?
  sorbet_path.to_s.shellescape
end

#sorbet_supports?(feature, version: nil) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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

  requirement.satisfied_by?(version)
end