Class: Tapioca::Commands::Dsl

Inherits:
CommandWithoutTracker 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, 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(requested_constants:, requested_paths:, outpath:, only:, exclude:, file_header:, 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, app_root: ".", halt_upon_load_error: true) ⇒ Dsl

Returns a new instance of Dsl.



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
# File 'lib/tapioca/commands/dsl.rb', line 30

def initialize(
  requested_constants:,
  requested_paths:,
  outpath:,
  only:,
  exclude:,
  file_header:,
  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,
  app_root: ".",
  halt_upon_load_error: true
)
  @requested_constants = requested_constants
  @requested_paths = requested_paths
  @outpath = outpath
  @only = only
  @exclude = exclude
  @file_header = file_header
  @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
  @app_root = app_root
  @halt_upon_load_error = halt_upon_load_error

  super()
end

Instance Method Details

#executeObject



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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/tapioca/commands/dsl.rb', line 97

def execute
  Loaders::Dsl.load_application(
    tapioca_path: @tapioca_path,
    eager_load: @requested_constants.empty? && @requested_paths.empty?,
    app_root: @app_root,
    halt_upon_load_error: @halt_upon_load_error,
  )

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

  all_requested_constants = @requested_constants + constants_from_requested_paths

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

  pipeline = create_pipeline

  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, all_requested_constants.join(" ")),
        gem_dir: @gem_dir,
        dsl_dir: @outpath.to_s,
        auto_strictness: @auto_strictness,
        compilers: pipeline.active_compilers,
      )
    end

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

#list_compilersObject



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
# File 'lib/tapioca/commands/dsl.rb', line 69

def list_compilers
  Loaders::Dsl.load_application(
    tapioca_path: @tapioca_path,
    eager_load: @requested_constants.empty? && @requested_paths.empty?,
    app_root: @app_root,
    halt_upon_load_error: @halt_upon_load_error,
  )

  pipeline = create_pipeline

  say("")
  say("Loaded DSL compiler classes:")
  say("")

  table = pipeline.compilers.map do |compiler|
    status = if pipeline.active_compilers.include?(compiler)
      set_color("enabled", :green)
    else
      set_color("disabled", :red)
    end

    [compiler.name, status]
  end

  print_table(table, { indent: 2 })
end