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