Coder Social home page Coder Social logo

hopsoft / fig Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 0.0 196 KB

The smart way to manage config settings for Rails and Ruby applications using YAML configuration files.

Home Page: http://hopsoft.github.com/fig/README.rdoc.html

License: MIT License

Ruby 100.00%

fig's Introduction

Fig

DRY up those magic numbers and hard coded strings into something more managable. Fig is the smart way to manage stuff that really belongs in a config file instead of scattered throughout your code.

Read the RDocs or jump right in with the tutorial video.

Why

Even though Ruby is a dynamic language and hard coded values aren’t as big a deal, it’s still good practice to have a centralized place to hold certain settings.

In the past I used a global Hash to store this stuff, but have always wanted something more powerful and elegant.

What

Fig is a simple to use configuration management tool for Ruby applications and libraries.

The primary features are:

  • Multiple configuration files

  • Dynamic updating and re-loading of configuration files

  • Simple dot-notation access to configuration settings

  • YAML access to configuration settings

  • Safe options to request settings that may not exist

  • Interpolation to help DRY up configuration files through reuse of settings

  • Thread safe

How

The simplest way to get started is to watch the 10 minute tutorial.

Installation

Fig is availabe as both a Gem and as a Rails Plugin.

To install as a Gem:

First, be sure that Github has been added as a gem source. (This only needs to be done once.)

gem sources -a http://gems.github.com

Second, install the Gem.

sudo gem install hopsoft-fig

To install as a Rails Plugin:

script/plugin install git://github.com/hopsoft/fig.git

Usage

Create a YAML file that will serve as one of the configuration files you plan to use. In a Rails application, I usually create the file config/app.yml, but you can name the file anything you like and can save it to any location within your appliation or library.

Instantiate a Fig object that is globally available to your application. In a Rails application, I generally do this in environment.rb.

CONFIG = Hopsoft::Fig.new(RAILS_ROOT + '/config/app.yml')

Start using your settings.

puts CONFIG.settings.message
puts CONFIG.yaml['message']
puts CONFIG.get_setting('message')

# returns nil instead of an error when the setting doesn't exist
puts CONFIG.get_setting('some.nested.setting.that.may.not.exist')

Reuse settings in your YAML file (This is a great way to apply the DRY principle to your configuration settings):

name: Nathan Hopkins
message: Hello from {fig:name}.

puts CONFIG.get_setting('message')
# outputs -> Hello from Nathan Hopkins.

Update the YAML file and load the changes without restarting your application.

CONFIG.load

Copyright © 2008 Hopsoft LLC, released under the MIT license

fig's People

Contributors

hopsoft avatar

Stargazers

Angus H. avatar Bob avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.