README.md in config-1.5.1 vs README.md in config-1.6.0

- old
+ new

@@ -297,9 +297,52 @@ raise a `Config::Validation::Error` containing a nice message with information about all the mismatches between the schema and your config. Check [dry-validation](https://github.com/dry-rb/dry-validation) for more details. +### Missing keys + +For an example settings file: + +```yaml +size: 1 +server: google.com +``` + +You can test if a value was set for a given key using `key?` and its alias `has_key?`: + +```ruby +Settings.key?(:path) +# => false +Settings.key?(:server) +# => true +``` + +By default, accessing to a missing key returns `nil`: + +```ruby +Settings.key?(:path) +# => false +Settings.path +# => nil +``` + +This is not "typo-safe". To solve this problem, you can configure the `fail_on_missing` option: + +```ruby +Config.setup do |config| + config.fail_on_missing = true + # ... +end +``` + +So it will raise a `KeyError` when accessing a non-existing key (similar to `Hash#fetch` behaviour): + +```ruby +Settings.path +# => raises KeyError: key not found: :path +``` + ### Environment variables See section below for more details. ## Working with environment variables