Econfig is a gem which allows you to easily configure your Rails applications in a multitude of ways.
Add this to your gemfile:
gem "econfig", :require => "econfig/rails"
Econfig extends the Rails configuration, you can use it like this:
MyApp::Application.config.app.aws_access_key
Where MyApp
is the name of your application and aws_access_key
is whatever
property you want to access. We recommend you add the shortcut module so you
can access config options directly:
module MyApp
extend Econfig::Shortcut
…
end
In config/application.rb
. This will give you:
MyApp.aws_access_key_id
which is obviously way more convenient. The rest of this README is going to assume that you added this shortcut.
Sometimes you want the application to crash early when a given config option is not set. Just add a bang (!) after the option name, and an error will be thrown if it is not set to a value which is present.
MyApp.aws_access_key_id!
You can specify configuration through:
- ENV variables
- Redis
- Relational database
- YAML files
- OSX Keychain
This allows you to set up econfig on most kinds of hosting solutions (EngineYard, Heroku, etc) without any additional effort, and to switch between them easily. The options are listed in descending order of preference.
Just set an environment variable whose name is the name of the option being accessed uppercased.
For example:
AWS_ACCESS_KEY_ID=xyz rails server
This is especially convenient for Heroku.
This needs to be explicitly enabled. In config/application.rb
add this line:
Econfig.use_database
You will also need to create a migration to create the necessary database tables:
rails generate econfig:migration
rake db:migrate
You can now set options by assigning them:
MyApp.aws_access_key_id = "xyz"
You may not use both Redis and relational database storage at the same time.
This needs to be explicitly enabled. In config/application.rb
add this line:
Econfig.use_redis Redis.new(:host => "myredis.com")
You can now set options by assigning them:
MyApp.aws_access_key_id = "xyz"
You may not use both Redis and relational database storage at the same time.
Add a yaml file to config/app.yml
. This should have a similar layout to config/database.yml
:
development:
aws_access_key_id: "xyz"
aws_secret_access_key: "xyz"
production:
aws_access_key_id: "xyz"
aws_secret_access_key: "xyz"
For the OSX keychain backend, see econfig-keychain.
MIT, see separate LICENSE.txt file