From 0f3529d8c6807eac5eb017d2396c02eb4d8a17c8 Mon Sep 17 00:00:00 2001 From: Kuba Krzempek Date: Mon, 10 Aug 2015 13:59:42 +0200 Subject: [PATCH] Update rails.md Add guideline on how to use envied defaults. --- rails.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rails.md b/rails.md index a429cea..6efc89a 100644 --- a/rails.md +++ b/rails.md @@ -398,3 +398,30 @@ class Raven::Event end end ``` + +## ENVied + +ENVied ensure presence and type of app's ENV-variables. To make the bootstraping of the app a quick process, it allows to assign default values to them. + +'Easily bootstrap' is quite the opposite of 'fail-fast when not all ENV-variables are present', hence it should be explicitly stated when defaults values are allowed: + +```ruby +# Envfile +development_or_test = ->{ ENV.fetch("RACK_ENV", "development").match(/development|test/) } +enable_defaults!(&development_or_test) + +variable :HOST, :string, default: 'host.dev' +variable :SENTRY_DSN, :string, default: '' + +variable :SSL_ENABLED, :boolean, default: false + +variable :API_KEY, :string, default: "api_key" +variable :CONSUMER_KEY, :string, default: "consumer_key" + +group :production do + variable :FORCE_SSL, :boolean +end +``` +The config enables the defaults in development or test environments, but still fail-fast in any other stage if any required ENV-variable is not set up. + +Without the fallback to `development` in `development_or_test` rake tasks won't work.