Class: Tapioca::Commands::Gem

Inherits:
Command
  • Object
show all
Includes:
SorbetHelper
Defined in:
lib/tapioca/commands/gem.rb

Constant Summary

Constants included from SorbetHelper

SorbetHelper::FEATURE_REQUIREMENTS, SorbetHelper::SORBET_BIN, SorbetHelper::SORBET_EXE_PATH_ENV_VAR, SorbetHelper::SORBET_GEM_SPEC

Instance Method Summary collapse

Methods included from SorbetHelper

#sorbet, #sorbet_path, #sorbet_supports?

Methods included from Tapioca::CliHelper

#rbi_formatter, #say_error

Constructor Details

#initialize(gem_names:, exclude:, prerequire:, postrequire:, typed_overrides:, outpath:, file_header:, doc:, include_exported_rbis:, number_of_workers: nil, auto_strictness: true, dsl_dir: DEFAULT_DSL_DIR, rbi_formatter: DEFAULT_RBI_FORMATTER) ⇒ Gem

Returns a new instance of Gem.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tapioca/commands/gem.rb', line 26

def initialize(
  gem_names:,
  exclude:,
  prerequire:,
  postrequire:,
  typed_overrides:,
  outpath:,
  file_header:,
  doc:,
  include_exported_rbis:,
  number_of_workers: nil,
  auto_strictness: true,
  dsl_dir: DEFAULT_DSL_DIR,
  rbi_formatter: DEFAULT_RBI_FORMATTER
)
  @gem_names = gem_names
  @exclude = exclude
  @prerequire = prerequire
  @postrequire = postrequire
  @typed_overrides = typed_overrides
  @outpath = outpath
  @file_header = file_header
  @number_of_workers = number_of_workers
  @auto_strictness = auto_strictness
  @dsl_dir = dsl_dir
  @rbi_formatter = rbi_formatter

  super()

  @loader = T.let(nil, T.nilable(Runtime::Loader))
  @bundle = T.let(nil, T.nilable(Gemfile))
  @existing_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
  @expected_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
  @doc = T.let(doc, T::Boolean)
  @include_exported_rbis = include_exported_rbis
end

Instance Method Details

#executeObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tapioca/commands/gem.rb', line 64

def execute
  require_gem_file

  gem_queue = gems_to_generate(@gem_names).reject { |gem| @exclude.include?(gem.name) }
  anything_done = [
    perform_removals,
    gem_queue.any?,
  ].any?

  Executor.new(gem_queue, number_of_workers: @number_of_workers).run_in_parallel do |gem|
    shell.indent do
      compile_gem_rbi(gem)
      puts
    end
  end

  if anything_done
    update_strictnesses(gem_queue.map(&:name), gem_dir: @outpath.to_s, dsl_dir: @dsl_dir) if @auto_strictness

    say("All operations performed in working directory.", [:green, :bold])
    say("Please review changes and commit them.", [:green, :bold])
  else
    say("No operations performed, all RBIs are up-to-date.", [:green, :bold])
  end
end

#sync(should_verify: false) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/tapioca/commands/gem.rb', line 91

def sync(should_verify: false)
  if should_verify
    say("Checking for out-of-date RBIs...")
    say("")
    perform_sync_verification
    return
  end

  anything_done = [
    perform_removals,
    perform_additions,
  ].any?

  if anything_done
    update_strictnesses([], gem_dir: @outpath.to_s, dsl_dir: @dsl_dir) if @auto_strictness

    say("All operations performed in working directory.", [:green, :bold])
    say("Please review changes and commit them.", [:green, :bold])
  else
    say("No operations performed, all RBIs are up-to-date.", [:green, :bold])
  end

  puts
end