Anyway Config
Rails plugin configuration using any source: YAML, secrets, environment.
Requires Rails 4.
Installation
Configure your gemspec
Gem::Specification.new do |s|
...
s.add_dependancy 'anyway_config', "~>0.1"
...
end
And then execute:
$ bundle
Or install it yourself as:
$ gem install anyway_config
Usage
Basic
Create configuration class:
module MyCoolGem
class Config < Anyway::Config
attr_config user: 'root', password: 'root', host: 'localhost'
end
end
attr_config creates accessors and default values. If you don't need default values just write:
attr_config :user, :password, host: 'localhost'
Your config will be filled up with values from RAILS_ROOT/config/my_cool_gem.yml, Rails.application.secrets.my_cool_gem (if using Rails) and ENV['MYCOOLGEM_*'].
Customize name
If you want to load config params from, for example, "cool.yml" (secrets, env), just add one line:
module MyCoolGem
class Config < Anyway::Config
config_name :cool
attr_config user: 'root', password: 'root', host: 'localhost', options: {}
end
end
How to set env vars
Environmental variables for your config should start with your module name (or config name if any), uppercased and underscore-free.
For example, if your module is called "MyCoolGem" then your env var "MYCOOLGEM_PASSWORD" is used as config.password.
Anyway Config supports nested (hashed) environmental variables. Just separate keys with double-underscore.
For example, "MYCOOLGEM_OPTIONS__VERBOSE" is transformed to config.options.verbose.
Config clear and reload
You can use clear and reload functions on your config (which do exactly what they state).
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request