dry-system
dry-system copied to clipboard
Allow custom environment variable prefixes in settings provider
Following on from the discourse conversation here.
When using the settings provider source, it currently isn't possible to assign a prefix to an environment variable name without also having the prefix in the internal setting name. We have written a patch and it seems straightforward enough to allow an optional prefix to be configured in the register_provider
block like so:
Application.register_provider(:settings, from: :dry_system) do
prefix { 'SOME_PREFIX_' }
settings do
setting :database_url, constructor: Types::String.constrained(filled: true)
end
I would like to submit a PR for this soon, if maintainers feel it would be helpful!
@solnic also mentioned that:
Having ability to have nested keys from env would be great too like STRIPE__API_KEY would be turned into settings.stripe.api_key.
I agree that would be a nice feature, so I would be happy to implement that too.
Sorry about bug
label, I can't seem to remove it. :(
I would have expected the prefix option to be passed in via register_provider
kwarg, I am guessing that you chose a provider method so that the implementation would be limited to the Settings provider?
I wonder if it would be helpful to have some sort of options pass-through from the register_provider
method into the provider initialization.
@alassek we went for a configuration option instead, PR up here: https://github.com/dry-rb/dry-system/pull/258