Skip to content

Instantly share code, notes, and snippets.

@Courey
Created September 8, 2014 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Courey/f26f82406c711d3cc2b5 to your computer and use it in GitHub Desktop.
Save Courey/f26f82406c711d3cc2b5 to your computer and use it in GitHub Desktop.
Figaro
# Figaro
## What is it?
It is used to configure open sourced Rails 3 and 4 apps where you need to include private credentials in your repo while still keeping them private.
## How does it do it?
It uses ENV (a collection of string key/value pairs) for configuration.
## How do I use it?
* include 'gem "figaro"' in your Gemfile
* bundle
* use 'rails generate figaro:install' to generate a commented config/application.yml file (which is .gitignore'ed)
* add your own configurations
## What does it give me?
The configuration will be available as key/value pairs in ENV.
## How does it do it?
Figaro.env passes directly through ENV, so it's just like using ENV itself. It does this instead of storing it as a copy.
in config/initializers/pusher.rb:
~~~
ruby Pusher.app_id = ENV["PUSHER_APP_ID"] Pusher.key = ENV["PUSHER_KEY"] Pusher.secret = ENV["PUSHER_SECRET"]
~~~
Through Figaro
~~~
ruby Pusher.app_id = Figaro.env.pusher_app_id Pusher.key = Figaro.env.pusher_key Pusher.secret = Figaro.env.pusher_secret
~~~
## What if my app requires Rails-environment-specific configuration?
you can namespace your configuration under a key for Rails.env
~~~
yaml HELLO: world decelopment: HELLO: developers production: HELLO: users
~~~
ENV["HELLO"] produces "developers" in development, "users" in production, and "world" otherwise.
## How do I use Figaro with Heroku?
From the command line using the heroku gem:
~~~
bash heroku config:add PUSHER_APP_ID=8926 heroku config:add PUSHER_KEY=0463644d89a340ff1132 heroku config:add PUSHER_SECRET=0eadfd9847769f94367b heroku config:add STRIPE_API_KEY=jHXKPPE0dUW84xJNYzn6CdWM2JfrCbPE heroku config:add STRIPE_PUBLIC_KEY=pk_HHtUKJwlN7USCT6nE5jiXgoduiNl3
~~~
Figaro has its own rake task to make this easier:
~~~
bash rake figaro:heroku
~~~
If you want to pass in an optional name of your Heroku app:
~~~
bash rake figaro:heroku[my-awesome-app]
~~~
If RAILS_ENV is configured on your Heroku server, Figaro will use that environment automatically in determining your proper configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment