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

Use Zeitwerk for loading components #634

Merged
merged 2 commits into from
Jun 13, 2021
Merged

Conversation

solnic
Copy link
Member

@solnic solnic commented Jun 7, 2021

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

  • Figure out how to "reset" Zeitwerk in specs because it keeps a global Registry which breaks specs when you run them all
  • Refactor AutoRegistration into a component loader where each instance handles a specific component type turned out a single loader is needed because zeitwerk can't handle multiple dirs that have the same parent
  • Refactor Setup#auto_registration into Setup#auto_register and refine its behavior to use the new loader
  • Figure out if Zeitwerk can support passing a namespace that is not part of a file path. ie lib/relations/users.rb where the constant is actually MyNamespace::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 all
  • add rom/compat for backward-compatibility APIs. Something like ROM.include(ROM::Compat[5.0]) should suffice sticking to plain require "rom/compat" for now
  • improve on_load handling because it actually yields path too, so we can infer component type from this easily
  • address RuboCop complaints
  • clean up commits

@solnic solnic force-pushed the 607-better-auto-registration branch 4 times, most recently from b14bd90 to 2d9f2f2 Compare June 11, 2021 14:11
@rom-rb rom-rb deleted a comment from viezly bot Jun 11, 2021
@solnic solnic marked this pull request as ready for review June 11, 2021 14:16
# @api private
def loader
@loader ||= Loader.new(@auto_register[0], **(@auto_register[1] || {})) if @auto_register
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way Loader is handled along with this components hash is going to be refactored separately. So, please ignore this part here.

@solnic solnic requested a review from flash-gordon June 11, 2021 14:20
@solnic solnic changed the title Improved auto registration Use Zeitwerk for loading components Jun 11, 2021
@solnic solnic added this to the 6.0.0 milestone Jun 11, 2021
@solnic solnic force-pushed the 607-better-auto-registration branch from 67400e0 to 69046a0 Compare June 12, 2021 16:26
- Replace AutoRegistration with a new Loader that uses Zeitwerk
- Deprecate `ROM::Setup#auto_registration` and move it to `rom/compat`

Refs #607
@solnic solnic force-pushed the 607-better-auto-registration branch from 69046a0 to f9fc522 Compare June 12, 2021 16:30
@rom-rb rom-rb deleted a comment from viezly bot Jun 12, 2021
@solnic solnic merged commit 458fb20 into master Jun 13, 2021
@solnic solnic deleted the 607-better-auto-registration branch June 13, 2021 07:14
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.

2 participants