Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #15.
Introduction
This engine provides two kinds of code:
Application-level code is added to the autoload paths by Rails, and it is not only autoloadable, but also reloadable.
Infraestructure-level code should not be reloadable, because if you decorate
ActiveRecord::Base
including a module, editing the source code of that module won't change the decoration.Infraestructure, as in railties or other gems, goes in
lib
.Refactor 1
First refactor would be to move infra to
lib
and let file paths reflect constant paths as usual. That leaves a directory that looks like this:and we need to issue manual
require
calls.We lose the neat organization that
app
provided, that is a step back for my taste, so let's revise that.Refactor 2
We can bring that organization back introducing folders:
That is better in my view, but we still need manual
require
calls.Refactor 3
That was precisely one of the things Zeitwerk wanted to address. We can define a loader that takes care of
lib
and forget aboutrequire
.Additionally, Zeitwerk supports organizational folders like the ones above via the
collapse
method. So we are all set.The parent application loader still manages
app
, and they do not interfere with each other. Also, the parent application can run inclassic
mode and it works (but please do not do that in 6.1!).