Class: Tapioca::Generators::Gem

Inherits:
Base
  • Object
show all
Defined in:
lib/tapioca/generators/gem.rb

Instance Method Summary collapse

Constructor Details

#initialize(gem_names:, gem_excludes:, prerequire:, postrequire:, typed_overrides:, default_command:, outpath:, file_header:, doc:, file_writer: FileWriter.new) ⇒ Gem

Returns a new instance of Gem.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tapioca/generators/gem.rb', line 21

def initialize(
  gem_names:,
  gem_excludes:,
  prerequire:,
  postrequire:,
  typed_overrides:,
  default_command:,
  outpath:,
  file_header:,
  doc:,
  file_writer: FileWriter.new
)
  @gem_names = gem_names
  @gem_excludes = gem_excludes
  @prerequire = prerequire
  @postrequire = postrequire
  @typed_overrides = typed_overrides
  @outpath = outpath
  @file_header = file_header

  super(default_command: default_command, file_writer: file_writer)

  @loader = T.let(nil, T.nilable(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)
end

Instance Method Details

#generateObject


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tapioca/generators/gem.rb', line 51

def generate
  require_gem_file

  gems_to_generate(@gem_names)
    .reject { |gem| @gem_excludes.include?(gem.name) }
    .each do |gem|
      say("Processing '#{gem.name}' gem:", :green)
      shell.indent do
        compile_gem_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(should_verify: false) ⇒ Object


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tapioca/generators/gem.rb', line 69

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