Class: Tapioca::Generator

Inherits:
Thor::Shell::Color
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/generator.rb

Constant Summary collapse

SORBET_CONFIG =
"sorbet/config"
DEFAULT_POSTREQUIRE =
"sorbet/tapioca/require.rb"
DEFAULT_OUTDIR =
"sorbet/rbi/gems"
DEFAULT_OVERRIDES =
T.let({
  # ActiveSupport overrides some core methods with different signatures
  # so we generate a typed: false RBI for it to suppress errors
  "activesupport" => "false",
}.freeze, T::Hash[String, String])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outdir: nil, prerequire: nil, postrequire: nil, command: nil, typed_overrides: nil) ⇒ Generator

Returns a new instance of Generator.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tapioca/generator.rb', line 40

def initialize(outdir: nil, prerequire: nil, postrequire: nil, command: nil, typed_overrides: nil)
  @outdir = T.let(Pathname.new(outdir || DEFAULT_OUTDIR), Pathname)
  @prerequire = T.let(prerequire, T.nilable(String))
  @postrequire = T.let(postrequire || DEFAULT_POSTREQUIRE, T.nilable(String))
  @command = T.let(command || default_command, String)
  @typed_overrides = T.let(typed_overrides || {}, T::Hash[String, String])
  @bundle = T.let(nil, T.nilable(Gemfile))
  @loader = T.let(nil, T.nilable(Loader))
  @compiler = T.let(nil, T.nilable(Compilers::SymbolTableCompiler))
  @existing_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
  @expected_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
  super()
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



27
28
29
# File 'lib/tapioca/generator.rb', line 27

def command
  @command
end

#outdirObject (readonly)

Returns the value of attribute outdir.



21
22
23
# File 'lib/tapioca/generator.rb', line 21

def outdir
  @outdir
end

#postrequireObject (readonly)

Returns the value of attribute postrequire.



25
26
27
# File 'lib/tapioca/generator.rb', line 25

def postrequire
  @postrequire
end

#prerequireObject (readonly)

Returns the value of attribute prerequire.



23
24
25
# File 'lib/tapioca/generator.rb', line 23

def prerequire
  @prerequire
end

#typed_overridesObject (readonly)

Returns the value of attribute typed_overrides.



29
30
31
# File 'lib/tapioca/generator.rb', line 29

def typed_overrides
  @typed_overrides
end

Instance Method Details

#build_gem_rbis(gem_names) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tapioca/generator.rb', line 55

def build_gem_rbis(gem_names)
  require_gem_file

  gems_to_generate(gem_names).map do |gem|
    say("Processing '#{gem.name}' gem:", :green)
    indent do
      compile_rbi(gem)
      puts
    end
  end

  say("All operations performed in working directory.", [:green, :bold])
  say("Please review changes and commit them.", [:green, :bold])
end

#sync_rbis_with_gemfileObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tapioca/generator.rb', line 71

def sync_rbis_with_gemfile
  anything_done = [
    perform_removals,
    perform_additions,
  ].any?

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