Class: Tapioca::Commands::Dsl

Inherits:
Command
  • Object
show all
Includes:
RBIFilesHelper, SorbetHelper
Defined in:
lib/tapioca/commands/dsl.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

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(requested_constants:, outpath:, only:, exclude:, file_header:, compiler_path:, tapioca_path:, should_verify: false, quiet: false, verbose: false, number_of_workers: nil, auto_strictness: true, gem_dir: DEFAULT_GEM_DIR, rbi_formatter: DEFAULT_RBI_FORMATTER) ⇒ Dsl

Returns a new instance of Dsl.



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/dsl.rb', line 28

def initialize(
  requested_constants:,
  outpath:,
  only:,
  exclude:,
  file_header:,
  compiler_path:,
  tapioca_path:,
  should_verify: false,
  quiet: false,
  verbose: false,
  number_of_workers: nil,
  auto_strictness: true,
  gem_dir: DEFAULT_GEM_DIR,
  rbi_formatter: DEFAULT_RBI_FORMATTER
)
  @requested_constants = requested_constants
  @outpath = outpath
  @only = only
  @exclude = exclude
  @file_header = file_header
  @compiler_path = compiler_path
  @tapioca_path = tapioca_path
  @should_verify = should_verify
  @quiet = quiet
  @verbose = verbose
  @number_of_workers = number_of_workers
  @auto_strictness = auto_strictness
  @gem_dir = gem_dir
  @rbi_formatter = rbi_formatter

  super()

  @loader = T.let(nil, T.nilable(Runtime::Loader))
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
96
97
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
128
129
130
# File 'lib/tapioca/commands/dsl.rb', line 65

def execute
  load_dsl_extensions
  load_application(eager_load: @requested_constants.empty?)
  abort_if_pending_migrations!
  load_dsl_compilers

  if @should_verify
    say("Checking for out-of-date RBIs...")
  else
    say("Compiling DSL RBI files...")
  end
  say("")

  outpath = @should_verify ? Pathname.new(Dir.mktmpdir) : @outpath
  rbi_files_to_purge = existing_rbi_filenames(@requested_constants)

  pipeline = Tapioca::Dsl::Pipeline.new(
    requested_constants: constantize(@requested_constants),
    requested_compilers: constantize_compilers(@only),
    excluded_compilers: constantize_compilers(@exclude),
    error_handler: ->(error) {
      say_error(error, :bold, :red)
    },
    number_of_workers: @number_of_workers
  )

  processed_files = pipeline.run do |constant, contents|
    constant_name = T.must(Tapioca::Runtime::Reflection.name_of(constant))

    if @verbose && !@quiet
      say_status(:processing, constant_name, :yellow)
    end

    compile_dsl_rbi(
      constant_name,
      contents,
      outpath: outpath,
      quiet: @should_verify || (@quiet && !@verbose)
    )
  end

  processed_files.each { |filename| rbi_files_to_purge.delete(T.must(filename)) }

  say("")

  if @should_verify
    perform_dsl_verification(outpath)
  else
    purge_stale_dsl_rbi_files(rbi_files_to_purge)
    say("Done", :green)

    if @auto_strictness
      say("")
      validate_rbi_files(
        command: default_command(:dsl, @requested_constants.join(" ")),
        gem_dir: @gem_dir,
        dsl_dir: @outpath.to_s,
        auto_strictness: @auto_strictness,
        compilers: pipeline.compilers
      )
    end

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