Sha256: dcb7cf9713c7a7a0ac9c7667a8862cabcfb9ba97f81a351d4fc4d62d06c07ac0

Contents?: true

Size: 1.49 KB

Versions: 21

Compression:

Stored size: 1.49 KB

Contents

# typed: strict
# frozen_string_literal: true

module Tapioca
  module SorbetHelper
    extend T::Sig

    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/___
      }.freeze,
      T::Hash[Symbol, ::Gem::Requirement],
    )

    sig { params(sorbet_args: String).returns(Spoom::ExecResult) }
    def sorbet(*sorbet_args)
      SPOOM_CONTEXT.srb(sorbet_args.join(" "), sorbet_bin: sorbet_path)
    end

    sig { returns(String) }
    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

    sig { params(feature: Symbol, version: T.nilable(::Gem::Version)).returns(T::Boolean) }
    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
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
tapioca-0.16.8 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.7 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.6 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.5 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.4 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.3 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.2 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.1 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.16.0 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.15.1 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.15.0 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.14.4 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.14.3 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.13.3 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.13.2 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.13.1 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.13.0 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.12.0 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.11.17 lib/tapioca/helpers/sorbet_helper.rb
tapioca-0.11.16 lib/tapioca/helpers/sorbet_helper.rb