Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading custom extensions in addition to custom compilers #1600

Open
olivier-thatch opened this issue Aug 10, 2023 · 2 comments
Open

Loading custom extensions in addition to custom compilers #1600

olivier-thatch opened this issue Aug 10, 2023 · 2 comments

Comments

@olivier-thatch
Copy link
Contributor

Hello,

I am trying to write a custom compiler for a gem that uses a DSL to add methods to Active Record model classes.

The problem is that the DSL simply calls define_singleton_method and does not maintain a list of the methods it defines. So there is no way to know which methods were defined by the gem when introspecting an Active Record model class.

After digging into the Tapioca repo, I saw that the compilers for delegated_type and has_secure_token have the same issue, and the workaround is to override the DSL methods to maintain a list of generated methods internally, using this extension.

I want to do something similar, however it looks like while Tapioca will look for custom compilers in the sorbet/tapioca/compilers directory, there is no equivalent for loading custom extensions. Extensions have to be loaded before the application, and the application is loaded before compilers, so I can't load the extension from the compiler.

Did I miss something, or is this something that is not currently supported? If not, would you be open to a PR to add support for this?

@KaanOzkan
Copy link
Contributor

Good point. I don't see a reason not to support this. Implementation can be similar to the load_dsl_compilers method

::Gem.find_files("tapioca/dsl/compilers/*.rb").each do |compiler|
require File.expand_path(compiler)
end

@Morriar
Copy link
Collaborator

Morriar commented Aug 11, 2023

We actually have some work in progress about this: 12255bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants