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

Fix integration with Rails when controllers_path is modified #216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/gruf/integrations/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ module Rails
#
class Railtie < ::Rails::Railtie
initializer 'gruf.initializer' do |app|
config.before_configuration do
config.after_initialize do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails is pretty finicky with initialization order changes between versions. @salmanasiddiqui - I think we're probably going to need to see some proof of life here that this change doesn't break Rails 7.0, 7.1, 7.2, and 8.0 installations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think eager load paths are frozen at the point of after_initialize so you won't be able to mutate it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for reviewing this, Im trying to figure if there is a good way to test this railtie. Any suggestions or relevant resources will be greatly appreciated

@zzak - after_initialize is used by gruf-rspec aswell, and I have tested this with Rails 7.1, it updated the autoloader correctly.
https://github.com/bigcommerce/gruf-rspec/blob/main/lib/gruf/rspec/railtie.rb#L25

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried EAGER_LOAD=true?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I did

# Remove autoloading of the controllers path from Rails' zeitwerk, so that we ensure Gruf's zeitwerk
# properly manages them itself. This allows us to manage code reloading and logging in Gruf specifically
app.config.eager_load_paths -= [::Gruf.controllers_path] if app.config.respond_to?(:eager_load_paths)
app.config.eager_load_paths -= [Gruf.controllers_path] if app.config.respond_to?(:eager_load_paths)
if ::Rails.respond_to?(:autoloaders) # if we're on a late enough version of rails
::Rails.autoloaders.each do |autoloader|
autoloader.ignore(Gruf.controllers_path)
Expand Down