Skip to content

Fix RailsAdapter::LoadedTooLateError with Zeitwerk#76

Merged
jaredonline merged 2 commits into
jaredonline:masterfrom
kg8m:fix-75-rails_adapter_loaded_too_late_error-with-zeitwerk
Feb 18, 2023
Merged

Fix RailsAdapter::LoadedTooLateError with Zeitwerk#76
jaredonline merged 2 commits into
jaredonline:masterfrom
kg8m:fix-75-rails_adapter_loaded_too_late_error-with-zeitwerk

Conversation

@kg8m
Copy link
Copy Markdown
Contributor

@kg8m kg8m commented Dec 23, 2022

Fixes #75.

Zeitwerk uses Ruby's built-in autoload, and defined? for an autoload constant always returns "constant". So defined?(::ApplicationController) always returns "constant" in some situations.

After this pull request, GoogleAuthenticatorRails gem will check if ApplicationController is loaded or not by Active Support's descendants instead of defined?. This new way doesn't depend on Ruby's autoload.

kg8m added 2 commits December 24, 2022 00:34
Zeitwerk uses Ruby's built-in `autoload`, and `defined?` for an autoload constant always returns `"constant"`.
So `defined?(::ApplicationController)` always returns `"constant"` in some situations.

After this commit, check if `ApplicationController` is loaded or not by Active Support's `descendants` instead
of `defined?`. This new way doesn't depend on Ruby's `autoload`.
@kg8m kg8m marked this pull request as ready for review December 23, 2022 15:49
@kg8m
Copy link
Copy Markdown
Contributor Author

kg8m commented Jan 5, 2023

@jaredonline
I am sorry to bother you, but could you please check this pull request?

@jaredonline
Copy link
Copy Markdown
Owner

Hey @kg8m and folks, sorry it's taken me 2 months to take a look at this. I will merge and roll this out today, thank you for the patch.

@jaredonline jaredonline merged commit d79788f into jaredonline:master Feb 18, 2023
@kg8m
Copy link
Copy Markdown
Contributor Author

kg8m commented Feb 19, 2023

Thanks a lot for your review and merge!

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

Successfully merging this pull request may close these issues.

RailsAdapter::LoadedTooLateError occurs if Zeitwerk is enabled

2 participants