-
Notifications
You must be signed in to change notification settings - Fork 133
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
Generating definitions for custom ruby app configuration #1001
Comments
👋 Hey @johnernaut, We're working on a custom loader solution that, I think, would solve this problem. |
@Morriar oh wow, awesome timing! I'll close this and keep an eye on that PR. Thanks! |
@Morriar Just as a heads up, when I test out the new functionality described in the PR (and point my gemfile to that branch) using the same require code above, I get the following output from Tapioca:
I am still using
|
While we're working on this, one hacky way to create a custom loader would be to define a custom DSL compiler under You even be able to trigger autoloads manually: # sorbet/tapioca/compilers/load_my_custom_rails_app.rb
require "../../../app/config/environment"
Rails.autoloaders.each(&:eager_load) |
@Morriar ah, interesting - thanks for looking into this! Really appreciate it. We don't actually use |
Wanted to share how I got this mostly working in our app with the structure defined in the original post and a # many other things redacted
app_root = File.expand_path("..", File.dirname(__FILE__))
ENV["APP_ENV"] ||= "development"
require "rubygems"
require "bundler/setup"
Bundler.require(:default, ENV["APP_ENV"])
require "zeitwerk"
loader = Zeitwerk::Loader.new
loader.push_dir("#{app_root}/app/models")
loader.push_dir("#{app_root}/app/services")
loader.push_dir("#{app_root}/app/rpc/controllers")
loader.push_dir("#{app_root}/app/workers")
loader.setup After creating a file in require_relative "../../../config/environment"
Zeitwerk::Loader.eager_load_all |
@johnernaut thanks for the
Managed to integrate them into Rails 7.1.1: config/application.rb class Application < Rails::Application
...
autoloaders.each do |autoloader|
autoloader.inflector.inflect(
'whatever_pb' => 'Whatever',
'whatever_services_pb' => 'Whatever')
end
$LOAD_PATH << "#{root}/grpc"
config.autoload_once_paths << "#{root}/grpc"
config.eager_load_paths << "#{root}/grpc"
# Google::Protobuf::DescriptorPool fails on reload! sorbet/tapioca/config.yml...
dsl:
exclude: # https://github.com/Shopify/tapioca/blob/main/manual/compilers.md
- Protobuf https://github.com/coinbase/protoc-gen-rbi#readme go install github.com/coinbase/protoc-gen-rbi@latest
p=/rails/grpc
grpc_tools_ruby_protoc \
--proto_path=$p --ruby_out=$p --grpc_out=$p \
--rbi_out=$p/../sorbet/rbi/grpc $p/whatever.proto |
Hello,
I have a custom Ruby app that I'd like to generate RBI files for. I do use active record and an
app/models
directory structure, but I'm handling loading myself in what's most likely a non-standard way, so I don't think that tapioca is able to find the files within my structure to create RBI definitions for them. My folder structure looks roughly like the following:I updated my
sorbet/tapioca/require.rb
file to attempt to require each file in myapp/models
folder individually so tapioca could find them, but that doesn't generate any definitions for them (there are no errors or warnings either):I was wondering if you all had any ideas as to how I might generate those definitions based on the above. Thanks!
The text was updated successfully, but these errors were encountered: