ConfigatronPlus
An addition to Configatron to make it easy to read configuration from default settings and multiple locations including environmental variables.
Configatron
Find out more at Configatron
Installation
Installation of ConfigatronPlus is easy, as it is just a RubyGem:
TODO: finish wrapping things up as gem
$ sudo gem install configatron-plus
Once installed you just need to require it:
require 'configatron-plus'
Usage
ConfigatronPlus stores all of its own configuration inside configatron. Use the following to see the current setup:
puts configatron.to_hash #dump it as a straight ruby code.
puts configatron.inspect #show the code you'd need to recreate the current config
Config
There are 5 parameters that can be configured, all of which have defaults. All 5 are located at
configatron.configatron_plus
Parameter | Use | Default |
---|---|---|
env_prefix | change this to change the prefix used in to look for values in the ENV | configatron_ |
fail_when_missing | change this to true to raise an error when a file in #sources is not found on the filesystem | false |
rc_name | the default name of the file to look for | config.rb |
source_files | the actual file name used for a given symbol | |
sources | The list of files and symbols to load | |
default
The default config looks like this when #inspect
configatron.configatron_plus.env_prefix = "configatron_"
configatron.configatron_plus.fail_when_missing = false
configatron.configatron_plus.rc_name = "config.rb"
configatron.configatron_plus.source_files = {:current=>"config.rb"}
configatron.configatron_plus.sources = [:current, :env]
Examples
Default
By default, ConfigurationPlus looks for a config.rb file in the current directory, and reads any Environmental Variables with a name that starts with configatron_
ConfigatronPlus.fetch_sources #Checks the current dir for config.rb and reads from environmental variables
Different default filename and prefix
To look for an alternate filename, set the rc_name parameter
configatron.configatron_plus.rc_name = "my_app.rb"
configatron.configatron_plus.env_prefix = "my_app_
ConfigatronPlus.fetch_sources #Checks the current dir for my_app.rb and reads from environmental variables starting with my_app_