Project

simpleconf

0.0
No commit activity in last 3 years
No release in over 3 years
Simple Configuration DSL that supports merging, locking and more.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

SimpleConf

Needed a simple configuration library for my gems. Made public so everyone can take advantage!

##Install [sudo] gem install simpleconf

##Usage

Simple Configuration

CONFIG = SimpleConf {
    host "localhost"
    port 80
    blacklist [1,2,3]
}

CONFIG.host # localhost
CONFIG.port # 80
CONFIG.blacklist # [1,2,3]

Nested Configuration

CONFIG = SimpleConf {
  server {
    ip "0.0.0.0"
    port 8080
  }

  workers 50

  security {
    admin {
      only_from "127.0.0.1"
    }

    max_logins 5
  }
}

CONFIG.server.ip # "0.0.0.0"
CONFIG.workers # 50
CONFIG.security.admin.only_from # "127.0.0.1"
CONFIG.security.max_logins # 5

Merging

default = SimpleConf {
  host "localhost"
  port 80
}

new_config = default.merge( #also merge!
  SimpleConf {
    port 9999
  }
)

new_config.host # "localhost"
new_config.port # 9999

Overriding

config = SimpleConf {
  host "localhost", :override => false
  port 80
}

config.host "google.com"
config.host # Still "localhost"
config.port 9999
config.port # 9999

Lock configuration

default = SimpleConf(:init_only => true){
  host "localhost"
}

default.port 80 #throws error!!!

File Configuration

# basic.conf

server "localhost"
ports [80, 8080, 3000]
auth {
  user "mike"
  pass "password"
}

# code.rb

conf = SimpleConf.load("basic.conf")
conf.server # localhost
conf.ports # [80, 8080, 3000]
conf.auth.user # mike
# etc

To see all examples/cases, see the spec file.