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

- old
+ new

@@ -8,11 +8,11 @@ `gem install configurations` or with Bundler -`gem 'configurations', '~> 1.4.0'` +`gem 'configurations', '~> 2.0.0.pre'` Configurations uses [Semver 2.0](http://semver.org/) ## Compatibility @@ -53,10 +53,27 @@ ``` MyGem.configuration.class #=> 'oooh wow' MyGem.configuration.foo.bar.baz #=> 'fizz' ``` +Undefined properties on an arbitrary configuration will return `nil` + +``` +MyGem.configuration.not_set #=> nil +``` + +If you want to define the behaviour for not set properties yourself, use `not_configured`. + +``` +module MyGem + not_configured 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 ``` @@ -85,10 +102,26 @@ ``` MyGem.configuration.foo #=> 'FOO' MyGem.configuration.bar.baz #=> 'FIZZ' ``` +Not configured properties on a restricted configuration will raise `NoMethodError` + +``` +MyGem.configuration.not_set #=> <#NoMethodError> +``` + +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| + warn :not_configured, "Please configure #{prop} or live in danger" + end +end +``` + ### Third way: Type Restricted Configuration If you want to make sure your configurations only accept one type, consider this option ``` @@ -119,22 +152,22 @@ ``` module MyGem include Configurations configurable :foo do |value| - # The return value is what gets assigned, unless it is nil, - # in which case the original value persists - # - value + ' ooooh my' + # The return value is what gets assigned, unless it is nil, + # in which case the original value persists + # + value + ' ooooh my' end configurable String, bar: :baz do |value| - # value is guaranteed to be a string at this point - # - unless %w(bi ba bu).include?(value) - raise ArgumentError, 'baz needs to be one of bi, ba, bu' - end + # value is guaranteed to be a string at this point + # + unless %w(bi ba bu).include?(value) + raise ArgumentError, 'baz needs to be one of bi, ba, bu' + end end end ``` Gives your users: @@ -164,11 +197,11 @@ ``` module MyGem include Configurations configurable :foo, :bar configuration_method :foobar do |arg| - foo + bar + arg + foo + bar + arg end end ``` Your users do: @@ -191,10 +224,10 @@ ``` module MyGem include Configurations configuration_defaults do |c| - c.foo.bar.baz = 'BAR' + c.foo.bar.baz = 'BAR' end end ``` ### Get a hash if you need it