0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
HostConfig is easy app configuration for Ruby apps that uses yml files to build up a nested OpenStruct for use globally in an app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 4.0

Runtime

 Project Readme

HostConfig

Simple per-host configuration for Rails 4.

Setup/Usage

First add it to your Gemfile:

gem 'host_config'

Then make an initializer (or add it to one you already have, like so):

AppConfig = HostConfig.init!

That's really it. This will attempt to load config/hosts/HOSTNAME.yml and assign an OpenStruct to AppConfig which you can then use all over your app. You can also override the hostname:

override_hostname = Rails.env.production? ? 'aws' :
                    Rails.env.staging? ? 'staging' :
                    nil
AppConfig = HostConfig.init! hostname: override_hostname

...or something similar, so that you can share config for production environments. This is a good alternative to environment variables. You can handle your configuration just like you already handle database.yml (eg, by not committing production config to the git repo, but adding it to each host out of band).

You can also add more values to it for things that aren't host-specific:

AppConfig.analytics_id = 'UA-XXXXXXXX-Y'
AppConfig.sanitize = Sanitize::Config::RELAXED
AppConfig.sanitize[:attributes]['a'] = %w{ target href name }
AppConfig.sanitize[:add_attributes] = {
  'a' => { 'target' => '_blank' }
}

...can be quite convenient.

Configuration

Configuration is in YAML files.

---
  force_ssl: true
  protocol: https
  application_host: myapp.com

  twitter:
    consumer: ABC
    secret: XYZ

  vegetables:
    - broccoli
    - carrots
    - corn

As simple as that. You can also setup common stuff in files prefixed with _. Eg, _defaults.yml, and load either before or after the stuff in the primary config:

---
  load_before:
    - defaults
  other_stuff: 'here'

This will look for _defaults.yml and deep-merge in the rest. You can also use load_after, which will of course override values in the primary config... why would you ever need this? I don't know :)

See the test/dummy app and the tests for the details if it isn't clear.