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

Subclasses of Lograge::Railtie aren't registered with Rails application #321

Open
dmolesUC opened this issue Dec 11, 2020 · 2 comments
Open

Comments

@dmolesUC
Copy link

Rails::Railtie depends on an inherited hook to build the list of Railtie classes (Rails::Railties, Rails::Engine.railties) that should be initialized and/or invoked at runtime (see this section in Rails::Application).

Because this hook is only called for classes that extend Rails::Railtie directly, extending Lograge::Railtie will result in Lograge::Railtie itself getting registered, but not its subclass. Some Railties that are designed for extension (e.g. Rails::Engine itself) deal with this by adding their own inherited hook which calls super.

I've worked this by modifying Railtie.subclasses directly, but it feels a bit hacky.

module MyModule
  class Railtie < Lograge::Railtie
    Rails::Railtie.subclasses.delete(Lograge::Railtie)
    Rails::Railtie.subclasses << self

    # ...rest of class

At any rate, IDK if this is something Lograge is interested in supporting, but if not, it might be nice to add a note to the documentation.

System info

  • Lograge version: 0.11.2
  • Rails version: 6.0.3.4
  • RVM version: 1.29.10
  • Ruby version: 2.7.1p83
  • OS: macOS Catalina (10.15.7)
@dmolesUC
Copy link
Author

(It's probably not strictly necessary for me to extend Lograge::Railtie in any case, but it seems a clearer way of documenting "this Railtie also initializes Lograge" than just calling require 'lograge' at the top without explicitly calling any Lograge code.)

@dmolesUC
Copy link
Author

FWIW, the workaround above no longer works in Rails 6.1, which removes the subclasses array and instead changes Railtie to extend ActiveSupport::DescendantsTracker.

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

1 participant