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

Allow Provider Sources to choose a custom superclass #275

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

alassek
Copy link
Contributor

@alassek alassek commented Jun 19, 2024

Relates to hanami/hanami#1417

The motivation for this is to allow consuming frameworks of dry-system to define their own superclass for providers, in order to add their own method apis to the class.

This is only used for user-defined providers with a block implementation.

External providers in a group do not allow this, because their superclass is defined ahead of time when they are added to the source registry. If an external provider source wants to use a different superclass, they can define a concrete class of their own instead.

The custom superclass is assumed to be a child of
Dry::System::Provider::Source.

Copy link
Member

@timriley timriley left a comment

Choose a reason for hiding this comment

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

This is really great, @alassek! Thank you so much for making it happen 😄

I've left a couple of notes for you that should hopefully be enough for you to get this into a ready-to-merge state.

Before we merge, though, would you be up for making a matching change to hanami that uses this? I think that this feature should allow us to get rid of our custom provider registrar in Hanami? That would be a nice outcome if possible — just one piece of customisation instead of two.

lib/dry/system/container.rb Outdated Show resolved Hide resolved
lib/dry/system/provider/source.rb Show resolved Hide resolved
lib/dry/system/provider_registrar.rb Outdated Show resolved Hide resolved
@alassek
Copy link
Contributor Author

alassek commented Jun 20, 2024

@timriley

Before we merge, though, would you be up for making a matching change to hanami that uses this?

Certainly, I wanted to pause to get feedback on the approach before continuing, but that is the next step and shouldn't require much effort.

@alassek alassek force-pushed the provider-class-override branch 3 times, most recently from d6b30e6 to 583cec6 Compare July 29, 2024 22:44
Copy link
Member

@timriley timriley left a comment

Choose a reason for hiding this comment

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

Thanks for refreshing this PR, @alassek!

It looks like you've found a nice arrangement here, with none of the provider build_source proc awkwardness that I introduced in in my spike on this at hanami/hanami#1417 (comment).

So this looks good to me overall! I've just left 2 comments for you. One is superficial, but the other one (regarding provider_source_options) is a more important aspect of the functionality. Let me know what you think about that, and after that is sorted, we can merge this in! 😄

lib/dry/system/provider_registrar.rb Outdated Show resolved Hide resolved
lib/dry/system/provider_registrar.rb Outdated Show resolved Hide resolved
@alassek alassek force-pushed the provider-class-override branch 6 times, most recently from 75c1073 to cb90a32 Compare August 1, 2024 03:25
Relates to hanami/hanami#1417

The motivation for this is to allow consuming frameworks of dry-system
to define their own superclass for providers, in order to add their own
method apis to the class.

The is only used for user-defined providers with a block implementation.

External providers in a group do not allow this, because their
superclass is defined ahead of time when they are added to the source
registry. If an external provider source wants to use a different
superclass, they can define a concrete class of their own instead.

The custom superclass is assumed to be a child of
Dry::System::Provider::Source.

In addition to `provider_source_class`, ProviderRegistrar contains
`provider_source_options` as an extension point for subclasses to send
custom intialization params to the source class.
@alassek
Copy link
Contributor Author

alassek commented Aug 1, 2024

@timriley Okay this should be caught up to all your latest feedback!

@alassek alassek requested a review from timriley August 1, 2024 03:33
@timriley
Copy link
Member

timriley commented Aug 1, 2024

@alassek FYI, I just pushed a commit here, which made the Hanami specs go green again on my machine.

Things were breaking in the tests that did .configure_provider(:db), because in that case the source class (Hanami::Providers::DB) inherited from Hanami::Provider::Source, so we needed the <= class comparator to allow the custom source options to be passed through.

@timriley
Copy link
Member

timriley commented Aug 3, 2024

@alassek Are you happy with this PR (and hanami/hanami#1446) in their current states?

@alassek
Copy link
Contributor Author

alassek commented Aug 4, 2024

@timriley Yes, thank you for figuring out the <= problem (I didn't even know you could do that!)

I'm happy with this.

@timriley timriley merged commit 97bf532 into dry-rb:main Aug 6, 2024
6 checks passed
@timriley
Copy link
Member

timriley commented Aug 6, 2024

Thanks for all your efforts getting this across the line, @alassek!!

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.

3 participants