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 multiple includes of Dry::Configurable #164

Merged
merged 4 commits into from
Jul 1, 2024
Merged

Conversation

timriley
Copy link
Member

@timriley timriley commented Jun 17, 2024

Instead of raising AlreadyIncludedError (now removed), update the method undef code in .included to handle already-undefined methods gracefully.

Allowing Dry::Configurable to be included multiple times across subclasses now allows for uses cases like a subclass adjusting various extension settings, e.g. config_class.

Instead of raising AlreadyIncludedError (now removed), update the method undef code in `.included` to handle already-undefined methods gracefully.

Allowing Dry::Configurable to be included multiple times across subclasses now allows for uses cases like a subclass adjusting various extension settings, e.g. `config_class`.
@timriley timriley marked this pull request as draft June 17, 2024 14:13
@timriley timriley self-assigned this Jun 17, 2024
lib/dry/configurable/errors.rb Show resolved Hide resolved
@@ -36,8 +34,8 @@ def included(klass)
prepend(Initializer)
Copy link
Member

Choose a reason for hiding this comment

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

Now that these lines are reachable, things are more tricky. include and prepend work differently, include will add a module to the ancestors' chain only once, whereas prepend does it every time. We should keep this in mind

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. I'll look to expand the testing to cover a few more possible edge cases before I mark this ready for a final review.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in Expand tests

@timriley
Copy link
Member Author

@flash-gordon FYI, this is the reason for this PR: hanami/hanami@86db090 (#1430)

Dry::System::Provider::Source already includes Dry::Configurable, providing a generic config object, which is fine in most circumstances. For the Hanami's DB provider source, however, we have fairly advanced config needs, so I want to provide a custom config API. By re-including Dry::Configurable and providing the config_class: option, we can now do that.

How does that feel to you?

I thought about adding a dedicated API to Provider::Source for specifying a custom config class, but that felt like overkill when I'm not sure how widely it will be needed, and our needs for the DB provider can be taken care of by a straightforward include. One downside of this approach is that it presumes knowledge of Provider::Source's internals (i.e. that it uses Dry::Configurable), but given the close relationship between Hanami and dry-rb, I think we can manage this.

@timriley
Copy link
Member Author

@flash-gordon I've expanded the tests to make sure nothing surprising happens with the multiple prepended #initialize methods. See the last commit above. It all looks good to me, things work as they should.

Given this, are you happy to see this be merged? Thanks again for checking!

@timriley timriley marked this pull request as ready for review June 29, 2024 03:51
@timriley timriley merged commit 2356764 into main Jul 1, 2024
12 checks passed
@timriley timriley deleted the allow-multiple-includes branch July 1, 2024 13:01
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