Class: Tapioca::Commands::Gem

Inherits:
Command
  • Object
show all
Includes:
RBIFilesHelper, 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, SorbetHelper::SORBET_PAYLOAD_URL, SorbetHelper::SPOOM_CONTEXT

Instance Method Summary collapse

Methods included from RBIFilesHelper

#duplicated_nodes_from_index, #index_rbi, #index_rbis, #location_to_payload_url, #validate_rbi_files

Methods included from SorbetHelper

#sorbet, #sorbet_path, #sorbet_supports?

Methods included from Tapioca::CliHelper

#netrc_file, #rbi_formatter, #say_error

Constructor Details

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

Returns a new instance of Gem.



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
62
63
64
65
66
67
# File 'lib/tapioca/commands/gem.rb', line 29

def initialize(
  gem_names:,
  exclude:,
  prerequire:,
  postrequire:,
  typed_overrides:,
  outpath:,
  file_header:,
  include_doc:,
  include_loc:,
  include_exported_rbis:,
  number_of_workers: nil,
  auto_strictness: true,
  dsl_dir: DEFAULT_DSL_DIR,
  rbi_formatter: DEFAULT_RBI_FORMATTER,
  halt_upon_load_error: true
)
  @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()

  @bundle = T.let(Gemfile.new(exclude), Gemfile)
  @existing_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
  @expected_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
  @include_doc = T.let(include_doc, T::Boolean)
  @include_loc = T.let(include_loc, T::Boolean)
  @include_exported_rbis = include_exported_rbis
  @halt_upon_load_error = halt_upon_load_error
end

Instance Method Details

#executeObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/tapioca/commands/gem.rb', line 70

def execute
  Loaders::Gem.load_application(
    bundle: @bundle,
    prerequire: @prerequire,
    postrequire: @postrequire,
    default_command: default_command(:require),
    halt_upon_load_error: @halt_upon_load_error,
  )

  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
    validate_rbi_files(
      command: default_command(:gem, @gem_names.join(" ")),
      gem_dir: @outpath.to_s,
      dsl_dir: @dsl_dir,
      auto_strictness: @auto_strictness,
      gems: @bundle.dependencies,
    )

    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, exclude: []) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/tapioca/commands/gem.rb', line 109

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

  anything_done = [
    perform_removals,
    perform_additions,
  ].any?

  if anything_done
    validate_rbi_files(
      command: default_command(:gem),
      gem_dir: @outpath.to_s,
      dsl_dir: @dsl_dir,
      auto_strictness: @auto_strictness,
      gems: @bundle.dependencies,
    )

    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