Module: Tapioca::Static::SymbolLoader

Extended by:
T::Sig, Runtime::Reflection, Tapioca::SorbetHelper
Defined in:
lib/tapioca/static/symbol_loader.rb

Constant Summary

Constants included from Runtime::Reflection

Runtime::Reflection::ANCESTORS_METHOD, Runtime::Reflection::CLASS_METHOD, Runtime::Reflection::CONSTANTS_METHOD, Runtime::Reflection::EQUAL_METHOD, Runtime::Reflection::METHOD_METHOD, Runtime::Reflection::NAME_METHOD, Runtime::Reflection::OBJECT_ID_METHOD, Runtime::Reflection::PRIVATE_INSTANCE_METHODS_METHOD, Runtime::Reflection::PROTECTED_INSTANCE_METHODS_METHOD, Runtime::Reflection::PUBLIC_INSTANCE_METHODS_METHOD, Runtime::Reflection::REQUIRED_FROM_LABELS, Runtime::Reflection::SINGLETON_CLASS_METHOD, Runtime::Reflection::SUPERCLASS_METHOD, Runtime::Reflection::UNDEFINED_CONSTANT

Constants included from Tapioca::SorbetHelper

Tapioca::SorbetHelper::FEATURE_REQUIREMENTS, Tapioca::SorbetHelper::SORBET_BIN, Tapioca::SorbetHelper::SORBET_EXE_PATH_ENV_VAR, Tapioca::SorbetHelper::SORBET_GEM_SPEC, Tapioca::SorbetHelper::SORBET_PAYLOAD_URL, Tapioca::SorbetHelper::SPOOM_CONTEXT

Class Method Summary collapse

Methods included from Runtime::Reflection

ancestors_of, are_equal?, class_of, constant_defined?, constantize, constants_of, descendants_of, file_candidates_for, inherited_ancestors_of, method_of, name_of, name_of_type, object_id_of, private_instance_methods_of, protected_instance_methods_of, public_instance_methods_of, qualified_name_of, resolve_loc, signature_of, singleton_class_of, superclass_of

Methods included from Runtime::AttachedClassOf

#attached_class_of

Methods included from Tapioca::SorbetHelper

sorbet, sorbet_path, sorbet_supports?

Class Method Details

.engine_symbols(gem) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tapioca/static/symbol_loader.rb', line 23

def engine_symbols(gem)
  gem_engine = engines.find do |engine|
    gem.contains_path?(engine.config.root.to_s)
  end

  return Set.new unless gem_engine

  paths = gem_engine.config.eager_load_paths.flat_map do |load_path|
    Pathname.glob("#{load_path}/**/*.rb")
  end

  symbols_from_paths(paths)
rescue
  Set.new
end

.gem_symbols(gem) ⇒ Object



40
41
42
# File 'lib/tapioca/static/symbol_loader.rb', line 40

def gem_symbols(gem)
  symbols_from_paths(gem.files)
end

.payload_symbolsObject



13
14
15
16
17
18
19
20
# File 'lib/tapioca/static/symbol_loader.rb', line 13

def payload_symbols
  unless @payload_symbols
    output = symbol_table_json_from("-e ''", table_type: "symbol-table-full-json")
    @payload_symbols = T.let(SymbolTableParser.parse_json(output), T.nilable(T::Set[String]))
  end

  T.must(@payload_symbols)
end

.symbols_from_paths(paths) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tapioca/static/symbol_loader.rb', line 45

def symbols_from_paths(paths)
  output = Tempfile.create("sorbet") do |file|
    file.write(Array(paths).join("\n"))
    file.flush

    symbol_table_json_from("@#{file.path.shellescape}")
  end

  return Set.new if output.empty?

  SymbolTableParser.parse_json(output)
end