README.md in config_default-0.1.2 vs README.md in config_default-0.2.0
- old
+ new
@@ -7,11 +7,11 @@
## Installation
Add this line to your application's Gemfile:
```ruby
-gem 'config_default'
+gem "config_default"
```
And then execute:
$ bundle install
@@ -102,11 +102,11 @@
```ruby
config = ConfigDefault.load(:app, key: nil) # Will not use key at all and result by full file
config = ConfigDefault.load(:app, key: "preprod") # Will search preprod key in file
```
-### Struct using
+### `#load_struct` method
If you want to use configuration as a struct object you can use `#load_struct` method.
Let's see an example with `database.yaml` config above:
```ruby
@@ -153,9 +153,27 @@
config.first.to_hash
# => { "second" => { "third" => "option" } }
config.first.second.to_hash
# => { "third" => "option" }
```
+
+### Using `ConfigDefault::Struct` without configuration load
+
+You can use `ConfigDefault::Struct` to achive ability to create config object from Hash objects.
+Here an example of creation struct object on the fly:
+
+```ruby
+config_on_the_fly = { first: { second: { third: "option" } } }
+config = ConfigDefault::Struct.new(attributes: config_on_the_fly, recursive: true)
+config.first.to_hash
+# => { "second" => { "third" => "option" } }
+config.first.second.third
+# => "option"
+config.first.lolkek
+# => StandardError: There is no option :lolkek in configuration.
+```
+
+`ConfigDefault::Struct` supports `recursive` and `allow_nil` options.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/skirushkin/config_default.