Class: Tapioca::Static::RequiresCompiler

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/static/requires_compiler.rb

Instance Method Summary collapse

Constructor Details

#initialize(sorbet_path) ⇒ RequiresCompiler

Returns a new instance of RequiresCompiler.



10
11
12
# File 'lib/tapioca/static/requires_compiler.rb', line 10

def initialize(sorbet_path)
  @sorbet_path = sorbet_path
end

Instance Method Details

#compileObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/tapioca/static/requires_compiler.rb', line 15

def compile
  config = Spoom::Sorbet::Config.parse_file(@sorbet_path)
  files = collect_files(config)
  names_in_project = files.to_h { |file| [File.basename(file, ".rb"), true] }
  files.flat_map do |file|
    collect_requires(file).reject { |req| names_in_project[req] }
  end.sort.uniq.map do |name|
    "require \"#{name}\"\n"
  end.join
end