Bogo Config

Hash based application configuration helpers, because snowflake configurations are evil.



Use the Bogo::Config directly to store configuration values:

require 'bogo-config'

config =
  :bind => {
    :address => '',
    :port => 8080
  :run_as => 'www-data'

puts config.get(:bind, :address)
puts config[:run_as]

Configuration files

A path to a configuration file can also be provided. Lets define the file:

# /tmp/bogo-config.json
  "bind": {
    "address": "",
    "port": 8080
  "run_as": "www-data"

and now we can load it:

require 'bogo-config'

config ='/tmp/bogo-config.json')

puts config.get(:bind, :address)
puts config[:run_as]


Subclassing Bogo::Config allows adding some structure to the configuration file. The Bogo::Lazy module is used to provide the #attribute method to describe the configuration:

require 'bogo-config'

class MyConfig < Bogo::Config
  attribute :bind, Smash, :coerce => proc{|v| v.to_smash}
  attribute :run_as, String, :default => 'www-data'

config ='/tmp/bogo-config.json')
puts config.get(:bind, :address)
puts config[:run_as]

Configuration file

Support for AttributeStruct configuration files is builtin. A helper class is provided as a visual nicety. The above JSON example could also be written as:

# /tmp/bogo-config.rb do
  bind do
    address ''
    port 8080
  run_as 'www-data'

Configuration file support

Currently the following serialization types are supported:

  • JSON
  • YAML
  • XML
  • AttributeStruct

Note on XML configuration files: The configuration must be contained within a <configuration> tag. The above example would then look like this:


Configuration directory

The path provided on initialization can also be a directory. The contents of the directory will be read in string sorted order and deep merged. Files can be a mix of supported types.

Ruby evaluation

Ruby evaluation is super awesome, except when you don't want it and then it's not super awesome. If a running process needs to disable Ruby based evaluation (a service perhaps), this can be done with an environment variable: