citrusbyte / settings

A special hash for application-wide settings.

This URL has Read+Write access

benalavi (author)
Tue Jun 16 02:43:56 -0700 2009
commit  c01fc68ff3e58e66b52c1ce8e2f49c3b559fc651
tree    c989f3baf71011bb7e7737619a13b9dd53fa6326
parent  05698b6d3661b6571198cb33d1f6922b7d633c8e
name age message
file .gitignore Tue Mar 17 19:33:45 -0700 2009 added missing files to gemspace + summary, adde... [benalavi]
file LICENSE Tue Mar 17 18:29:09 -0700 2009 initial version of settings [benalavi]
file README.markdown Tue Jun 16 02:43:56 -0700 2009 fix gemspec, update README [benalavi]
file Rakefile Tue Mar 17 18:29:09 -0700 2009 initial version of settings [benalavi]
directory lib/ Sat Apr 25 14:45:32 -0700 2009 fixed rails gem-dependency loading [benalavi]
directory rails/ Sat Apr 25 14:45:32 -0700 2009 fixed rails gem-dependency loading [benalavi]
file settings.gemspec Tue Jun 16 02:43:56 -0700 2009 fix gemspec, update README [benalavi]
file settings.gemspec.erb Tue Jun 16 02:43:56 -0700 2009 fix gemspec, update README [benalavi]
directory test/ Wed Mar 18 12:20:33 -0700 2009 cleaned up files, added some documentation, and... [benalavi]
README.markdown

Settings

A special hash for application-wide settings.

Description

Small and simple specialized Hash which is helpful for storing immutable, required key/value pairs to be loaded from a YAML file.

New instances of SettingsHash are readonly -- any attempt to write to the Hash after initialization will fail with a TypeError.

Any attempt to read a key which is not set will raise a SettingsHash::SettingNotFound error.

SettingsHash supports an optional namespace which can be used to define multiple groups of settings within a single .yml file. For example, "test" and "development" might be different namespaces for different running environments.

Usage

General

settings = SettingsHash.new('path/to/settings.yml')
settings = SettingsHash.new('path/to/settings.yml', 'foo') => loads settings under the 'foo' namespace

Rails

Put your environment-specific settings.yml in config/settings.yml. It may look something like this:

development:
  memcached: true
test:
  memcached: false

This file will automatically be loaded into a Settings global which can be accessed like a normal Hash:

Settings[:memcached] => true (development environment)
Settings[:memcached] => false (test environment)

Installation

$ sudo gem install settings

Testing

Tests require Contest gem:

http://github.com/citrusbyte/contest

License

Copyright (c) 2009 Ben Alavi for Citrusbyte

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.