A9n is a simple tool to keep ruby/rails apps configuration maintanable and verifiable. It supports Rails 3.x, 4.x and Ruby 2.0. 2.1, 2.2, 2.3. Ruby 1.8 and Rails 2.x are not supported since version 0.1.2. Ruby 1.9 is not supported since version 0.4.0.
Why it's named a9n? It's a numeronym for application (where 9 stands for the number of letters between the first a and last n, similar to i18n or l10n).
Add this line to your application's Gemfile:
And then execute:
configuration.yml file into the config
directory. When none fo these files exists,
exception is thrown.
If both file exist, content of
configuration.yml is validated. It means that
all keys existing in example file must exist in local file - in case of missing
A9n::MissingConfigurationVariablesError is thrown with the explanation what is missing.
Set application root and load configuration by adding to your
after budler requires:
. = File.expand_path('../..', __FILE__) .
This step is not required ,if you don't use
a9n in the environment settings or initializers.
It works with
Rails by default. If you want to use
A9n with non-rails app
you may need to tell that to A9n by:
.local_app = MyApp
You can access any variable defined in configuration files by delegating it to
defaults: email_from: 'email@example.com' production: app_host: 'knapik.cc' development: app_host: 'localhost:3000'
is accessible by:
.app_host # => `knapik.cc` in production and `localhost:3000` in development .email_from # => `firstname.lastname@example.org` in both envs
Custom and multiple configuration files
If you want to split configuration, you can use multiple files. All files from
config/a9n are loaded by default, but you may pass custom paths as an argument to
A9n.load('config/facebook.yml', 'config/mongoid.yml'). In such cases config items are accessible through the scope consistent with the file name.
E.g. if you have
defaults: username: "joe" api_key: "1234asdf"
You can access it by:
.mandrill.username # => `joe` .mandrill.api_key # => `1234asdf`
Mapping ENV variables
Sometimes, you don't want to store a single secret value in the repo and you prefer having it in ENV variable. You can easily map it using
:env symbol as a value:
production: access_token: :env
If you use capistrano and you feel safe enough to keep all your instance ( staging, production) configuration in the repository, you may find it useful to use capistrano extensions.
Just add an instance configuration file e.g.
configuration.yml.production (NOTE: file extension must be consistent with the capistrano stage) and add
to your Capfile. This way
configuration.yml on each deploy.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request