-
-
Notifications
You must be signed in to change notification settings - Fork 288
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
Dynamically load development or test default values #266
Comments
Priority of variables loaded, from lowest to highest:
With this in mind, I don't think source ".env.yml"
source ".env.test.yml", if: -> { Rails.env.test? }
load ".env.yml"
load ".env.test.yml", if: -> { Rails.env.test? }
provide ".env.yml"
provide ".env.test.yml", if: -> { Rails.env.test? }
I think the strategy for loading really depends on if you expect value files to act like cascading stylesheets, where you can provide overrides in special conditions, then multiple DSL
source ".env.yml", key: :base
source ".env.yml", key: :test, if: -> { Rails.env.test? } I guess it all depends on what your goals are, but I think separating the idea of |
Update: After mulling this over some more, I'm leaning toward a single YAML configuration file with the ability to key the file according to the application environment. To define the application environment (since Figaro will no longer be Rails-dependent), I'm adding the # env.rb
environment key: "APP_ENV", default: "development"
defaults "env.yml"
string :stripe_publishable_key
string :stripe_secret_key
decimal :price, default: "9.99" # env.yml
stripe_publishable_key: "pk_test_NlsxCBp2TPGWyQeHUFw4uj4L"
stripe_secret_key: "sk_test_iHBheVvfdegliMwizMi2uiOe"
production:
stripe_publishable_key: "pk_live_uoExPgxfIG7bBXMAMyqHfB9b"
stripe_secret_key: "sk_live_KbhHZzgpzWIEsOoBOnatXUjo" As for the When it comes to committing multiple default values for a given key, let's say for the
I'm not sure what to do about this one just yet either. I don't like the idea of multiple YAML configuration files because it's harder to track down what values are where. Plus it's more likely that something that's not supposed to get committed does get committed. Here's what option 2 might look like in practice: # env.rb
environment key: "APP_ENV", default: "development"
defaults "env.yml"
string :hello, default: { development: "developer", test: "computer" } Anyway, just dumping some thoughts here. Feel free to chime in! |
Using a Rails app as an example, a developer may want to load certain default values when
Rails.env.development?
and others when running the test suite andRails.env.test?
. Both of these cases should use the sameEnvfile
. So what's the most intuitive way to load different default values based on the environment, keeping in mind that Figaro 2.0 is dropping the explicit Rails dependency?Some initial thoughts:
I'd like to be explicit about what's being loaded and avoid hidden conventions. Think about Bundler and how you
source "https://rubygems.org"
at the top of everyGemfile
. The Bundler team could have made that the default source since it is 95% of the time, but they opted for clarity.I'd love to get others' thoughts on these two ideas and suggestions for more ideas. Thank you!
The text was updated successfully, but these errors were encountered: