README.md in envied-0.6.3 vs README.md in envied-0.7.0
- old
+ new
@@ -1,15 +1,29 @@
# ENVied [![travis](https://secure.travis-ci.org/eval/envied.png?branch=master)](https://secure.travis-ci.org/#!/eval/envied)
### TL;DR ensure presence and type of your app's ENV-variables.
-This gem will provide:
+Features:
-* A fail-fast check for presence of ENV-variables
-* A fail-fast check whether the values can be coerced to the correct type
-* Access to typed ENV-variables (instead of just strings)
+* check for presence and correctness of ENV-variables
+* access to typed ENV-variables (integers, booleans etc. instead of just strings)
+* check the presence and correctness of Heroku config
+## Contents
+
+* [Quickstart](#quickstart)
+* [Installation](#installation)
+* [Configuration](#configuration)
+ * [Types](#types)
+ * [Groups](#groups)
+ * [Defaults](#defaults)
+* [Rails](#rails)
+* [Command-line interface](#command-line-interface)
+* [Testing](#testing)
+* [Developing](#developing)
+* [Contributing](#contributing)
+
## Quickstart
### 1) Configure
After [successful installation](#installation), define some variables in `Envfile`:
@@ -21,11 +35,11 @@
```
### 2) Check for presence and coercibility
```ruby
-# file: some file that'll be run on initialization (e.g. `config/application.rb`)
+# during initialization
ENVied.require
```
This will throw an error if:
* not both `ENV['FORCE_SSL']` and `ENV['PORT']` are present.
@@ -38,10 +52,28 @@
```ruby
ENVied.PORT # => 3001
ENVied.FORCE_SSL # => false
```
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'envied'
+
+...then bundle:
+
+ $ bundle
+
+...then for Rails applications:
+
+ $ bundle exec envied init:rails
+
+...or for non-Rails applications:
+
+ $ bundle exec envied init
+
## Configuration
### Types
The following types are supported:
@@ -152,36 +184,61 @@
# All in one line:
ENVied.require(:default, ENV['RACK_ENV'], (ENV['CI'] ? :ci : :not_ci))
```
-## command-line interface
+## Rails
+**tl;dr** use the `init:rails`-task to generate the necessary files for a Rails app (see [installation](#installation)).
+
+---
+
+With the [Spring](https://github.com/rails/spring) preloader (which is part of the default Rails setup nowadays) it's a bit tricky when to do `ENVied.require`.
+
+The first time you execute a command (say `bin/rails console`), Spring will start the server from which subsequent commands fork from.
+Currently [a bug in Spring](https://github.com/rails/spring/pull/267#issue-28580171) causes the initialization of the forked process to use the server's `ENV` instead of the actual `ENV`.
+
+So if your `ENV` is not valid the first time you start Spring...:
+
+ # spring server *not* running
+ $ bin/rails console
+ # spring server started
+ # error raised: Please set the following ENV-variables: FORCE_SSL (RuntimeError)
+
+...it won't be valid for subsequent commands (even when you provide the correct variables):
+
+ # spring server still running
+ # FORCE_SSL=1 bin/rails console
+ # error raised: Please set the following ENV-variables: FORCE_SSL (RuntimeError)
+
+So while doing a `ENVied.require` in `config/application.rb` would seem perfectly fine, it won't work in the default 'springified' Rails setup.
+
+The workaround (which the `init:rails`-task will generate) is to move the `ENVied.require` to Spring's `after_fork`-callback.
+If you want to change Rails' config based on ENV-variables you should put this in an `after_fork`-callback as well:
+
+```ruby
+# config/initializers/envied.rb as generated by 'bundle exec envied init:rails'
+ENVied.springify do
+ ENVied.require(:default, ENV['RAILS_ENV'])
+
+ Rails.configuration.force_ssl = ENVied.FORCE_SSL
+end
+```
+
+## Command-line interface
+
```bash
$ envied help
Commands:
envied check # Checks whether you environment contains the defined variables
envied check:heroku # Checks whether a Heroku config contains the defined variables
envied check:heroku:binstub # Generates a shell script for the check:heroku-task
envied help [COMMAND] # Describe available commands or one specific command
envied init # Generates a default Envfile in the current working directory
+ envied init:rails # Generate all files needed for a Rails project
```
-## Installation
-
-Add this line to your application's Gemfile:
-
- gem 'envied'
-
-...then bundle:
-
- $ bundle
-
-...and generate the `Envfile`:
-
- $ bundle exec envied init
-
## Testing
```bash
bundle install --binstubs
@@ -193,10 +250,9 @@
## Developing
```bash
bin/pry --gem
```
-
## Contributing
1. Fork it ( http://github.com/eval/envied/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)