bigcommerce / gruf

gRPC Ruby Framework
https://github.com/bigcommerce/gruf
MIT License
626 stars 73 forks source link

Gruf.controllers_path unloaded even in client mode #171

Closed Freubert closed 2 years ago

Freubert commented 2 years ago

Please describe the issue

When running Gruf client in a Rails setup the autoload_path app/rpc will be removed from the config.

How to Reproduce

Steps to reproduce the behavior:

  1. Call a class or module which resides inside app/rpc from Rails console in production mode
  2. uninitialized constant error will occur

What should happen?

app/rpc shouldn't be removed from autoload_path in client mode.

Anything else we should know?

Workaround

A workaround seems to be to add app/rpc explicitly to Rails eager_load_path.

splittingred commented 2 years ago

@Freubert This is intentional; two separate Zeitwerk instances cannot manage the same directory; see: https://github.com/bigcommerce/gruf/blob/main/lib/gruf/integrations/rails/railtie.rb#L29

Allowing Rails to manage autoloading for app/rpc will cause conflicts in Zeitwerk in non-classic autoloading setups, which will be required in Rails 7+. gruf is aligning to that - it is recommended instead that you not put classes that are not Gruf controllers in app/rpc, instead placing them in other directories (such as app/models, lib/, etc).

Freubert commented 2 years ago

Thanks @splittingred for the clarification.