Class: Tapioca::Commands::Dsl

Inherits:
Command
  • Object
show all
Defined in:
lib/tapioca/commands/dsl.rb

Instance Method Summary collapse

Methods included from Tapioca::CliHelper

#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, rbi_formatter: DEFAULT_RBI_FORMATTER) ⇒ Dsl

Returns a new instance of Dsl.



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
49
50
51
52
53
# File 'lib/tapioca/commands/dsl.rb', line 23

def initialize(
  requested_constants:,
  outpath:,
  only:,
  exclude:,
  file_header:,
  compiler_path:,
  tapioca_path:,
  should_verify: false,
  quiet: false,
  verbose: false,
  number_of_workers: nil,
  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
  @rbi_formatter = rbi_formatter

  super()

  @loader = T.let(nil, T.nilable(Runtime::Loader))
end

Instance Method Details

#executeObject



56
57
58
59
60
61
62
63
64
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
# File 'lib/tapioca/commands/dsl.rb', line 56

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)

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