Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Yet Another Configuration Helper Tool
tag: 0.2.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
features
gem_tasks
lib
spec
.gitignore
.rspec
.rvmrc
.yardopts
Gemfile
LICENSE
README.rdoc
Rakefile
yacht.gemspec

README.rdoc

Yacht

Yacht is an application configuration gem that lets you define settings for multiple environments in YAML files. It is similar to AppConfig with additional features like:

  • use of ClassyStruct for improved performance over OpenStruct

  • protection of sensitive settings by specifying a whitelist in a YAML file

  • easy override of nested keys (not pretty with YAML references)

  • no need for an initializer or constant to store loaded values (just use Yacht.my_key)

Installation

  • Rails: Add this to your Gemfile and run the bundle command.

    gem "yacht"
  • Outside of rails, just require the gem as usual:

    require 'rubygems'
    require 'yacht'

Getting Started

Step 1: YAML files

First create two (or more) YAML files in the same directory to define your settings:

# config/yacht/base.yml (required)
production:
  cdn_host: 1.2.3.4
  super_secret_info:
    aws_key: foofoo
    twitter_key: barbar
test:
  cdn_host: localhost
  super_secret_info:
    # you can safely overwrite a single value in a nested key
    # YAML references (& and *) don't let you do this
    #   see https://gist.github.com/979804 for an explanation
    aws_key: bazbaz

# config/yacht/whitelist.yml (required)
# any keys specified here can be used as a whitelist filter:
#   Yacht::Loader.to_hash(:apply_whitelist? => true)
#   or
#   Yacht::Loader.to_classy_struct(:apply_whitelist? => true)
#   (by default the whitelist is ignored)
# NOTE: the whitelist is ignored when using Yacht.my_key or Yacht['my_key']
#       you have to use Yacht::Loader#to_hash or
#       Yacht::Loader#to_classy_struct to use the whitelist
- super_secret_info

# config/yacht/local.yml (optional)
# any values set in local.yml will override values set in base.yml
# useful for development and testing
production:
  cdn_host: localhost

Step 2: Use Yacht.my_key or Yacht['my_key']

  • Rails:

    # now you can access any key set in your YAML files with:
    #   Yacht.my_key
  • Outside of rails, you need to tell Yacht where your YAML files are stored, and what environment you want to use.

    Yacht::Loader.dir          = '/path/to/YAML/dir'
    Yacht::Loader.environment  = 'my_environment'
    Yacht.my_key

License

Yacht is licensed under the MIT License with one addition: The Software shall be used for Good, not Evil.

Something went wrong with that request. Please try again.