Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Defer accessing config until after user-provided block is evaluated #16

Merged
merged 2 commits into from
Sep 29, 2019

Conversation

timriley
Copy link
Member

This makes it possible for users to e.g. use dry-system plugins that add new settings, which otherwise raises a Dry::Configurable::AlreadyDefinedConfig error if any config has been accessed previously.

This would be fixed anyway once we address dry-rb/dry-configurable#70, but that's a larger piece of work, and I'd like to make dry-system-rails more flexible in the meantime.

The reason I actually needed this is because I wanted to use the dry-system settings component, which requires use :env to be added within the Dry::System::Rails.container do ... end block. use :env adds a new setting, so we need to make sure this block is evaluated as early as possible to avoid that error above.

@solnic Does this look OK to you?

This makes it possible for users to e.g. use dry-system plugins that add new settings, which otherwise raises a Dry::Configurable::AlreadyDefinedConfig if any config has been accessed previously

default_options = {
root: ::Rails.root,
system_dir: ::Rails.root.join('config/system'),
Copy link

Choose a reason for hiding this comment

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

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.

@solnic
Copy link
Member

solnic commented Sep 26, 2019

@solnic Does this look OK to you?

Yes but we need a test that covers this change too. Reproducing your use case in a spec would be enough.

spec/integration/container/using_plugins_spec.rb Outdated Show resolved Hide resolved
spec/integration/container/using_plugins_spec.rb Outdated Show resolved Hide resolved
spec/integration/container/using_plugins_spec.rb Outdated Show resolved Hide resolved
@timriley
Copy link
Member Author

@solnic OK, so short of a major overhaul of the whole testing infrastructure here (like we just discussed, to support testing specific aspects of this Railtie's behaviour in complete isolation), are you fine with the test I've just added now? It demonstrates the behaviour that this change supports.

And that test is red on master, green here.

@timriley timriley merged commit 21fd970 into master Sep 29, 2019
@timriley timriley deleted the defer-accessing-config branch September 29, 2019 10:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants