lib/tapioca/generator.rb in tapioca-0.1.5 vs lib/tapioca/generator.rb in tapioca-0.2.0

- old
+ new

@@ -7,10 +7,15 @@ module Tapioca class Generator < ::Thor::Shell::Color extend(T::Sig) DEFAULT_OUTDIR = "sorbet/rbi/gems" + DEFAULT_OVERRIDES = T.let({ + # ActiveSupport overrides some core methods with different signatures + # so we generate a typed: false RBI for it to suppress errors + "activesupport" => "false", + }.freeze, T::Hash[String, String]) sig { returns(Pathname) } attr_reader :outdir sig { returns(T.nilable(String)) } attr_reader :prerequire @@ -35,10 +40,11 @@ @prerequire = T.let(prerequire, T.nilable(String)) @postrequire = T.let(postrequire, T.nilable(String)) @command = T.let(command || default_command, String) @typed_overrides = T.let(typed_overrides || {}, T::Hash[String, String]) @bundle = T.let(nil, T.nilable(Gemfile)) + @loader = T.let(nil, T.nilable(Loader)) @compiler = T.let(nil, T.nilable(Compilers::SymbolTableCompiler)) @existing_rbis = T.let(nil, T.nilable(T::Hash[String, String])) @expected_rbis = T.let(nil, T.nilable(T::Hash[String, String])) super() end @@ -89,19 +95,24 @@ sig { returns(Gemfile) } def bundle @bundle ||= Gemfile.new end + sig { returns(Loader) } + def loader + @loader ||= Loader.new(bundle) + end + sig { returns(Compilers::SymbolTableCompiler) } def compiler @compiler ||= Compilers::SymbolTableCompiler.new end sig { void } def require_gem_file say("Requiring all gems to prepare for compiling... ") - bundle.require_bundle(prerequire, postrequire) + loader.load_bundle(prerequire, postrequire) say(" Done", :green) puts end sig { returns(T::Hash[String, String]) } @@ -265,10 +276,10 @@ def compile_rbi(gem) compiler = Compilers::SymbolTableCompiler.new gem_name = set_color(gem.name, :yellow, :bold) say("Compiling #{gem_name}, this may take a few seconds... ") - typed_sigil = typed_overrides.fetch(gem.name, "true") + typed_sigil = typed_overrides[gem.name] || DEFAULT_OVERRIDES[gem.name] || "true" content = compiler.compile(gem) content.prepend(rbi_header(command, typed_sigil)) FileUtils.mkdir_p(outdir)