README.md in dotenv-rails-2.5.0 vs README.md in dotenv-rails-2.6.0
- old
+ new
@@ -1,6 +1,6 @@
-# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv) [![Gem Version](https://badge.fury.io/rb/dotenv.svg)](https://badge.fury.io/rb/dotenv) [![Join the chat at https://gitter.im/bkeepers/dotenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bkeepers/dotenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.svg?branch=master)](https://travis-ci.org/bkeepers/dotenv) [![Gem Version](https://badge.fury.io/rb/dotenv.svg)](https://badge.fury.io/rb/dotenv) [![Join the chat at https://gitter.im/bkeepers/dotenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bkeepers/dotenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Shim to load environment variables from `.env` into `ENV` in *development*.
Storing [configuration in the environment](http://12factor.net/config) is one of the tenets of a [twelve-factor app](http://12factor.net). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.
@@ -161,10 +161,25 @@
# This is a comment
SECRET_KEY=YOURSECRETKEYGOESHERE # comment
SECRET_HASH="something-with-a-#-hash"
```
+### Required Keys
+
+If a particular configuration value is required but not set, it's appropriate to raise an error.
+
+To require configuration keys:
+
+```ruby
+# config/initializers/dotenv.rb
+
+Dotenv.require_keys("SERVICE_APP_ID", "SERVICE_KEY", "SERVICE_SECRET")
+```
+
+If any of the configuration keys above are not set, your application will raise an error during initialization. This method is preferred because it prevents runtime errors in a production application due to improper configuration.
+
+
## Frequently Answered Questions
### Can I use dotenv in production?
dotenv was originally created to load configuration variables into `ENV` in *development*. There are typically better ways to manage configuration in production environments - such as `/etc/environment` managed by [Puppet](https://github.com/puppetlabs/puppet) or [Chef](https://github.com/chef/chef), `heroku config`, etc.
@@ -173,15 +188,22 @@
If you use this gem to handle env vars for multiple Rails environments (development, test, production, etc.), please note that env vars that are general to all environments should be stored in `.env`. Then, environment specific env vars should be stored in `.env.<that environment's name>`.
### What other .env* files can I use?
-`dotenv-rails` will load the following files, starting from the bottom. The first value set (or those already defined in the environment) take precedence:
+`dotenv-rails` will override in the following order (highest defined varible overrides lower):
-- `.env` - The Original®
-- `.env.development`, `.env.test`, `.env.production` - Environment-specific settings.
-- `.env.local` - Local overrides. This file is loaded for all environments _except_ `test`.
-- `.env.development.local`, `.env.test.local`, `.env.production.local` - Local overrides of environment-specific settings.
+| Hierarchy Priority | Filename | Environment | Should I `.gitignore`it? | Notes |
+| ------------------ | ------------------------ | -------------------- | --------------------------------------------------- | ------------------------------------------------------------ |
+| 1st (highest) | `.env.development.local` | Development | Yes! | Local overrides of environment-specific settings. |
+| 1st | `.env.test.local` | Test | Yes! | Local overrides of environment-specific settings. |
+| 1st | `.env.production.local` | Production | Yes! | Local overrides of environment-specific settings. |
+| 2nd | `.env.local` | Wherever the file is | Definitely. | Local overrides. This file is loaded for all environments _except_ `test`. |
+| 3rd | `.env.development` | Development | No. | Shared environment-specific settings |
+| 3rd | `.env.test` | Test | No. | Shared environment-specific settings |
+| 3rd | `.env.production` | Production | No. | Shared environment-specific settings |
+| Last | `.env` | All Environments | Depends (See [below](#should-i-commit-my-env-file)) | The Original® |
+
### Should I commit my .env file?
Credentials should only be accessible on the machines that need access to them. Never commit sensitive information to a repository that is not needed by every development machine and server.