README.md in basic_config-0.0.1 vs README.md in basic_config-0.0.2

- old
+ new

@@ -1,7 +1,9 @@ # BasicConfig +[![Build Status](https://secure.travis-ci.org/stephan778/basic_config.png)](http://travis-ci.org/stephan778/basic_config) + Friendly configuration wrapper. If you find yourself using things like: ```ruby AppConfig = YAML.load_file('config/app.yml')[environment].symbolize_keys ``` @@ -23,11 +25,16 @@ $ gem install basic_config ## Usage ```ruby +# Loading config is simple settings = BasicConfig.load_file('config.yml') +# It's a simple variable, you can create as many as you like. +# You can use constants for convinience: +AppConfig = BasicConfig.load_file('config/app.yml') +DatabaseConfig = BasicConfig.load_file('config/database.yml') # Access your configuration with simple method calls settings.some_param # At any level of nesting @@ -43,29 +50,29 @@ If your file has sections for different environments: ``` development: host: localhost port: 123 -test +test: host: localhost port: 456 ``` then you can load the right environment with `load_env`: ```ruby AppConfig = BasicConfig.load_env('config.yml', Rails.env) ``` ## Why should I use it instead of plain Hash variables? -### It raises errors when you unintentionally read non-existent keys: +### It raises errors when you unintentionally read non-existent keys If you are using a `Hash`: ```ruby secret_token = AppConfig[:something] ``` -and for some reason your configuration does not have `:something` in it - you'll -get a `nil`. Worst case: this `nil` will live inside your system compromising +and for some reason your configuration does not have `:something` in it (or you +make a typo) - you'll get a `nil`. Worst case: this `nil` will live inside your system compromising or corrupting some data until you finally notice and track it down back to this line. If you are using a `BasicConfig`: ```ruby secret_token = AppConfig.something @@ -76,11 +83,11 @@ *Note:* There is also an `include?` method which you can use to check if particular key exist in your config - `AppConfig.include?(:something)`. Additionaly, for some keys it makes sense to get a `nil` when they do not exist and for this purpose there is a `[]` method which is delegated to underlying hash. -### Works recursively. +### Works recursively If your YAML is more than 1 level deep then simple `symbolize_keys` is not going to be enough: ```ruby AppConfig[:something]['have_to_use_string_here'] ``` @@ -88,12 +95,18 @@ With BasicConfig above would look like this: ```ruby AppConfig.something.have_to_use_string_here ``` -### Easier to test. +### Easier to test You can stub out any config variable just like a normal method in your tests. ```ruby AppConfig.stub(:something).and_return('anything') ``` + +## Gotchas + +The only thing that I can think of is be aware that you can not use Ruby Object +method names for your configuration variable names (`puts`, `print`, `raise`, +`display`, etc, you can see the full list with `BasicConfig.methods`).