Code Monkey home page Code Monkey logo

figgy's Introduction

figgy

Gem Version Build Status Dependency Status Code Climate Coverage Status

Provides convenient access to configuration files in various formats, with support for overriding the values based on environment, hostname, locale, or any other arbitrary thing you happen to come up with.

Documentation

yardocs

Installation

Just like everything else these days. In your Gemfile:

gem 'figgy'

Overview

Set it up (say, in a Rails initializer):

AppConfig = Figgy.build do |config|
  config.root = Rails.root.join('etc')

  # config.foo is read from etc/foo.yml
  config.define_overlay :default, nil

  # config.foo is then updated with values from etc/production/foo.yml
  config.define_overlay(:environment) { Rails.env }

  # Maybe you need to load XML files?
  config.define_handler 'xml' do |contents|
    Hash.from_xml(contents)
  end
end

Access it as a dottable, indifferent-access hash:

AppConfig.foo.some_key
AppConfig["foo"]["some_key"]
AppConfig[:foo].some_key

Multiple root directories may be specified, so that configuration files live in more than one place (say, in gems):

AppConfig = Figgy.build do |config|
  config.root = Rails.root.join('etc')
  config.add_root Rails.root.join('vendor/etc')
end

Precedence of root directories is in reverse order of definition, such that the root directory added first (typically the one immediately within the application) has highest precedence. In this way, defaults can be inherited from libraries, but then overridden when necessary within the application.

Caveats

Because the objects exposed by figgy are often hashes, all of the instance methods of Hash (and, of course, Enumerable) are available along the chain. But note that this means you can not use key names such as size or each with the dottable access style:

AppConfig.price.bulk   #=> 100.00
AppConfig.price.each   #=> attempts to invoke Hash#each
AppConfig.price[:each] #=> 50.00

Thanks

This was written on Enova's dime/time.

figgy's People

Contributors

pd avatar bwthomas avatar joshcheek avatar

Watchers

James Cloos 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.