README.md in configurations-2.0.0.pre vs README.md in configurations-2.0.0

- old
+ new

@@ -8,17 +8,17 @@ `gem install configurations` or with Bundler -`gem 'configurations', '~> 2.0.0.pre'` +`gem 'configurations', '~> 2.0.0'` Configurations uses [Semver 2.0](http://semver.org/) ## Compatibility -Compatible with MRI 1.9.2 - 2.1, Rubinius, jRuby +Compatible with MRI 1.9.2 - 2.2, Rubinius 2.2, jRuby 1.7 and 9K ## Why? There are various ways to do configurations, yet there seems to be a broad consensus on the `MyGem.configure do ... end` idiom. So instead of rolling your own, you can add this gem to your gem and get that functionality for free, plus some goodies you may want @@ -59,21 +59,30 @@ ``` MyGem.configuration.not_set #=> nil ``` -If you want to define the behaviour for not set properties yourself, use `not_configured`. +If you want to define the behaviour for not set properties yourself, use `not_configured`. You can either define a catch-all `not_configured` which will be executed whenever you call a value that has not been configured and has no default: ``` module MyGem not_configured do |prop| raise NoMethodError, "#{prop} must be configured" end end ``` +Or you can define finer-grained callbacks: +``` +module MyGem + not_configured my: { nested: :prop } do |prop| + raise NoMethodError, "#{prop} must be configured" + end +end +``` + ### Second way: Restricted Configuration If you just want some properties to be configurable, consider this option ``` @@ -112,11 +121,11 @@ If you want to define the behaviour for not set properties yourself, use `not_configured`. This will only affect properties set to configurable. All not configurable properties will raise `NoMethodError`. ``` module MyGem - not_configured do |prop| + not_configured :awesome, :nice do |prop| # omit the arguments to get a catch-all not_configured warn :not_configured, "Please configure #{prop} or live in danger" end end ``` @@ -217,11 +226,18 @@ ``` MyGem.configuration.foobar('ARG') #=> 'FOOBARARG' ``` +configuration methods can also be installed on nested properties using hashes: +``` +configuration_method foo: :bar do |arg| + foo + bar + arg +end +``` + ### Defaults: ``` module MyGem include Configurations @@ -237,11 +253,11 @@ MyGem.configuration.to_h #=> a Hash ``` ### Configure with a hash where needed -Sometimes your users will have a hash of configuration values which are not handy to press into the block form. In that case, they can use `from_h` inside the `configure` block to either read in the full or a nested configuration. +Sometimes your users will have a hash of configuration values which are not handy to press into the block form. In that case, they can use `from_h` inside the `configure` block to either read in the full or a nested configuration. With a everything besides arbitrary configurations, `from_h` can also be used outside the block. ``` yaml_hash = YAML.load_file('configuration.yml') MyGem.configure do |c| @@ -250,17 +266,17 @@ end ``` ### Some caveats -The `to_h` from above is along with `method_missing`, `object_id` and `initialize` the only purposely defined API method which you can not overwrite with a configuration value. +The `to_h` from above is along with `method_missing`, `object_id` and `initialize` and `singleton_class` the only purposely defined API method which you can not overwrite with a configuration value. Apart from these methods, you should be able to set pretty much any property name you like. `Configuration` inherits from `BasicObject`, so even `Kernel` and `Object` method names are available. ## Contributing YES! Let's make this awesome. Write tests for your added stuff, bonus points for feature branches. If you don't have the time to write a fix, raise an issue. ### Copyright -Copyright © 2014 Beat Richartz. See LICENSE.txt for further details. +Copyright © 2015 Beat Richartz. See LICENSE.txt for further details.