-
Notifications
You must be signed in to change notification settings - Fork 504
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
Override predefined variables #38
Conversation
ie. so changing variables in .env actually works
I was thinking about how to solve the unicorn problem a few weeks ago and didn't have any great ideas. I think it's really important to not override defined env variables by default. Any ideas on how to make this configurable? |
One option, while not very elegant, would be to add a This would keep the functionality totally abstracted from dotenv itself, and allow people to plugin a simple call to something like As an example, I've got a gem I use to work on ecosystems of multiple projects, that contains some scripts and commands to "do things with" the projects that are part of the ecosystem. One of those things is a launcher script that can be used (like foreman) to run processes in a Procfile. Those launchers are actually kicked off by foreman at the root of the ecosystem, so I have to do some unsetting of a couple
|
I just realized the same restrictions for being able to configure that behavior (dotenv is loaded before initializers are run, so where would you configure dotenv behavior) also sort of apply to unsetting stuff manually... If you were to do that in an initializer, it would just be unsetting the values completely since dotenv would've already tried to load. You could of course call This is a tough one. It seems any configuration would need to be done prior to launching an application + dotenv autoloading, is that right? In that case the only options I see are a config file or an env var (both of which seem kinda funny for a library which serves a very specific purpose of loading a config file and populating env vars). |
Sorry, not trying to spam here, but just had one more thought - what about a custom require for the gem? It might be a little awkward (?), but maybe something like |
@bkeepers, oh so I'm not alone with the unicorn problem. I couldn't find examples of anyone @markrebec interesting solution with the custom require. Are there any other gems offering up alternate |
I'm not aware of any other gems controlling configuration or behavior in that way, and the more I think about it, the less fond I am of the solution. I started fleshing out the idea in #41 but it seems extremely restrictive and kind of overkill to control one single aspect of configuration this way, and it doesn't provide any flexibility for the future if there are other behaviors or configuration options we want to control. The idea of another gem I think may be a bit more in the right direction, but it still has the same pitfalls as the custom require unfortunately. |
Yeah, I'm not loving any of the options at the moment. That's not to say I don't think Another idea is to make dotenv more stateful, keeping track of which env vars it loaded, and allow calling |
👍 for |
It's important to not override defined environment variables. The environment should know better than the app. So I'm going to close this for now. Please feel free to start another discussion about ways to handle reloading. |
ie. so changing values in
.env
actually worksThe problems we're trying to solve with dotenv:
environment variables to be override-able in each new fork [FAIL - the values
are inherited from their parernt]
Which is why we need to change the current behaviour of dotenv to override predefined variables.
(Perhaps there is a way of configuring the gem to have either behaviour?)