Add docsite for version 0.8

This commit is contained in:
Piotr Solnica 2019-10-04 10:58:59 +02:00
parent 4755eb6033
commit 25de66ac0d
No known key found for this signature in database
GPG Key ID: 66BF2FDA7BA0F29C
2 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,55 @@
---
title: Introduction & Usage
description: Thread-safe configuration mixin
layout: gem-single
order: 7
type: gem
name: dry-configurable
sections:
- testing
---
### Introduction
`dry-configurable` is a simple mixin to add thread-safe configuration behaviour to your classes. There are many libraries that make use of configuration, and each seemed to have their own implementation with a similar or duplicate interface, so we thought it was strange that this behaviour had not already been encapsulated into a reusable gem, hence `dry-configurable` was born.
### Usage
`dry-configurable` is extremely simple to use, just extend the mixin and use the `setting` macro to add configuration options:
```ruby
class App
extend Dry::Configurable
# Pass a block for nested configuration (works to any depth)
setting :database do
# Can pass a default value
setting :dsn, 'sqlite:memory'
end
# Defaults to nil if no default value is given
setting :adapter
# Pre-process values
setting(:path, 'test') { |value| Pathname(value) }
# Passing the reader option as true will create attr_reader method for the class
setting :pool, 5, reader: true
# Passing the reader attributes works with nested configuration
setting :uploader, reader: true do
setting :bucket, 'dev'
end
end
App.config.database.dsn
# => "sqlite:memory"
App.config.database.dsn = 'jdbc:sqlite:memory'
App.config.database.dsn
# => "jdbc:sqlite:memory"
App.config.adapter
# => nil
App.config.path
# => #<Pathname:test>
App.pool
# => 5
App.uploader.bucket
# => 'dev'
```

View File

@ -0,0 +1,27 @@
---
title: Testing
layout: gem-single
name: dry-configurable
---
### How to reset the config to its original state on testing environment
update `spec_helper.rb` :
```ruby
require "dry/configurable/test_interface"
# this is your module/class that extended by Dry::Configurable
module AwesomeModule
enable_test_interface
end
```
and on spec file (`xxx_spec.rb`) :
```ruby
before(:all) { AwesomeModule.reset_config }
# or
before(:each) { AwesomeModule.reset_config }
```