Class: Tapioca::Commands::Gem

Inherits:
Command
  • Object
show all
Includes:
RBIHelper, 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 RBIHelper

#validate_rbi_files

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.



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
62
# File 'lib/tapioca/commands/gem.rb', line 27

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



65
66
67
68
69
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
# File 'lib/tapioca/commands/gem.rb', line 65

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
    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) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/tapioca/commands/gem.rb', line 98

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
    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