Moving config mess from environment files to config.yml

If your environments/*.rb look like a repetitive mess, its time to get a config.yml!

  • overview of your configuration
  • dry code
  • (optional) not check in all the passwords/keys of your app (only check in config.example.yml), great for open-source apps
  • Can be loaded without loading the environment (e.g. small rake tasks)
# lib/cfg.rb
CFG = YAML.load("config/config.yml")

# config/application.rb
require "cfg"

# config/config.yml
common: &common
    airbrake_key: xxx
    google_analytics_key: yyy

  <<: *common
  host: 'localhost'

  <<: *common
  host: 'localhost'

  <<: *common
  host: ''

# config/application.rb
config.action_mailer.default_url_options = {:host => CFG[:host]}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s