Use Zeitwerk for loading components #634
Merged
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.
This replaces AutoRegistration with a Loader that uses Zeitwerk. I'll open a separate PR once this is merged with the actual API improvements, what this PR does essentially, is providing a better and simpler implementation for loading components. Things like options and behavior still need to be improved.
TODO
AutoRegistration
into a component loaderwhere each instance handles a specific component typeturned out a single loader is needed because zeitwerk can't handle multiple dirs that have the same parentSetup#auto_registration
intoSetup#auto_register
and refine its behavior to use the new loaderlib/relations/users.rb
where the constant is actuallyMyNamespace::Users
-it cannot and this is fine, because this is a weird use case that's completely non-standard so I'll move this behavior to a backward-compatibility "layer"silly me missed the fact that Zeitwerk actually supports passing "namespace" option to push_dir, so this use case is supported after allrom/compat
for backward-compatibility APIs.Something likesticking to plainROM.include(ROM::Compat[5.0])
should sufficerequire "rom/compat"
for nowon_load
handling because it actually yields path too, so we can infer component type from this easily