0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A library for help to configure applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.6.4
>= 0

Runtime

>= 0
 Project Readme

Config Context: ¶ ↑

Your minimal and DSL config context…

Installing¶ ↑

The latest stable version is published in rubygems.

gem install config_context

How to use, well, look this useful examples:¶ ↑

require 'rubygems'
require 'config_context'

##
# Puts all your configuration context in a block
ConfigContext.configure do |config|

  config.a = "Value of a"
  config.b = "Value of b"
  config.c = { also:=>"complex", :values=>['like', 'this'] }
end

##
# Retrieve your properties
puts ConfigContext.a
puts ConfigContext.b
puts ConfigContext.c

##
# Check the presence of a property
puts ConfigContext.b if ConfigContext.b?

##
# Load your config from a YAML file
begin	
  ConfigContext.configure("settings.yml")
rescue ConfigContext::Error => e
  fail e.message
end

##
# Load your config from a JSON file
begin	
  ConfigContext.configure("settings.json")
rescue ConfigContext::Error => e
  fail e.message
end

puts ConfigContext

##
# Reset the context !!!
ConfigContext.erase!
ConfigContext.to_hash == {} #must true

##
# Use contexts
ConfigContext.configure(:context=>"ContextA", 'settings.json')

puts ConfigContext.ContextA[:property]

##
# Retrive with default values
ConfigContext.fetch(:donotexist, "default value") -> "default value"
ConfigContext.donotexist? -> false

ConfigContext.fetch!(:donotexist, "default value") -> "default value"
ConfigContext.donotexist? -> true

TODO¶ ↑

* Sugestions are wellcome guys