tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

Prototype for custom app loaders

Open Morriar opened this issue 3 years ago • 1 comments

Motivation

Currently Tapioca is unable to generate DSL RBIs for applications that are not Rails applications.

This PR provides a way for the user to pass a custom loader so Tapioca can load the application then run the RBI compilers.

To do so, one can create a file under sorbet/tapioca/loader.rb with the following content:

Tapioca.load_for_dsl do
  print "Loading my custom application application..."
  require_relative "../../lib/post.rb"
  puts " Done"

  load_dsl_compilers
  require_relative "../../lib/compilers/some_custom_compiler.rb"
end

Tests

See automated tests.

Morriar avatar Apr 28 '22 21:04 Morriar

About the user experience, is there a simple way we could detect if the developer forgot to invoke load_dsl_defaults?

One idea I had, but that requires changing the interface, would be separating loading the app from loading custom compilers and having Tapioca deciding when to invoke load_dsl_defaults. E.g.:

Tapioca.eager_load_app do
  require ...
end

Tapioca.load_dsl_compilers do
  require ...
end

# And then, inside Tapioca
def execute
  instance_exec(&Tapioca.eager_load_app_block)
  load_dsl_defaults
  instance_exec(&Tapioca.load_dsl_compilers_block)
end

WDYT?

vinistock avatar Apr 29 '22 14:04 vinistock