dry-configurable 0.8.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +88 -19
- data/LICENSE +1 -1
- data/README.md +17 -28
- data/dry-configurable.gemspec +29 -15
- data/lib/dry-configurable.rb +2 -0
- data/lib/dry/configurable.rb +23 -131
- data/lib/dry/configurable/class_methods.rb +103 -0
- data/lib/dry/configurable/compiler.rb +45 -0
- data/lib/dry/configurable/config.rb +81 -115
- data/lib/dry/configurable/constants.rb +12 -0
- data/lib/dry/configurable/dsl.rb +62 -0
- data/lib/dry/configurable/dsl/args.rb +58 -0
- data/lib/dry/configurable/{error.rb → errors.rb} +5 -1
- data/lib/dry/configurable/instance_methods.rb +46 -0
- data/lib/dry/configurable/methods.rb +32 -0
- data/lib/dry/configurable/setting.rb +98 -12
- data/lib/dry/configurable/settings.rb +43 -63
- data/lib/dry/configurable/test_interface.rb +3 -5
- data/lib/dry/configurable/version.rb +3 -1
- metadata +33 -17
- data/.codeclimate.yml +0 -23
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.travis.yml +0 -27
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -17
- data/Rakefile +0 -12
- data/lib/dry/configurable/settings/argument_parser.rb +0 -50
- data/rakelib/rubocop.rake +0 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d6c2b78240f829b83467c0edd12a5c4dc59d4d7b0fdb5aa9e44fdfc5e3031e13
|
|
4
|
+
data.tar.gz: 506974ab79b93359fbac5305fa76860f13b13047dd85a76dffbbdebc500d2d93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e1bf6f3ea8ebd9bae2d0bd759cd3f81fd591d8df3a11e675b23acc54f1228ec3311bdab3c04f6b85e5db01ca718d1ed64b2347fa2bcbb3d439c127a6efdfe39
|
|
7
|
+
data.tar.gz: 2ff1ff49ddee94891d5e920e5b48c2c4a5d50d7a2e56c4c4df7c68b46cd61c4270ee375ad6c5a9d6b95f4ca8b01b4d4dd397e2f350a4d6aa584c0d3d87e4442c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,20 +1,85 @@
|
|
|
1
|
-
##
|
|
1
|
+
## unreleased
|
|
2
2
|
|
|
3
|
-
## Fixed
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
### Fixed
|
|
5
|
+
|
|
6
|
+
- You can use `:settings` as a config key again (issue #80) (@solnic)
|
|
7
|
+
- Setting value is lazy-evaluated now, which fixes some cases where a constructor could crash with a `nil` value (@solnic)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
[Compare v0.11.0...master](https://github.com/dry-rb/dry-configurable/compare/v0.11.0...master)
|
|
11
|
+
|
|
12
|
+
## 0.11.0 2020-02-15
|
|
13
|
+
|
|
14
|
+
Complete rewrite of the library while keeping the public API intact. See #78 for a detailed overview.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Accessing config in a parent class no longer prevents you from adding more settings in a child class (@solnic)
|
|
19
|
+
- (internal) New low-level Setting and Config API (@solnic)
|
|
20
|
+
- (internal) `config` objects use method_missing now (@solnic)
|
|
21
|
+
|
|
22
|
+
[Compare v0.10.0...v0.11.0](https://github.com/dry-rb/dry-configurable/compare/v0.10.0...v0.11.0)
|
|
23
|
+
|
|
24
|
+
## 0.10.0 2020-01-31
|
|
25
|
+
|
|
26
|
+
YANKED because the change also broke inheritance for classes that used `configured` before other classes inherited from them.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Inheriting settings no longer defines the config object. This change fixed a use case where parent class that already used its config would prevent a child class from adding new settings (@solnic)
|
|
31
|
+
|
|
32
|
+
[Compare v0.9.0...v0.10.0](https://github.com/dry-rb/dry-configurable/compare/v0.9.0...v0.10.0)
|
|
33
|
+
|
|
34
|
+
## 0.9.0 2019-11-06
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- Support for reserved names in settings. Some Kernel methods (`public_send` and `class` specifically) are not available if you use access settings via method call. Same for methods of the `Config` class. You can still access them with `[]` and `[]=`. Ruby keywords are fully supported. Invalid names containing special symbols (including `!` and `?`) are rejected. Note that these changes don't affect the `reader` option, if you define a setting named `:class` and pass `reader: true` ... well ... (flash-gordon)
|
|
40
|
+
- Settings can be redefined in subclasses without a warning about overriding exsting methods (flash-gordon)
|
|
41
|
+
- Fix warnings about using keyword arguments in 2.7 (koic)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
[Compare v0.8.3...v0.9.0](https://github.com/dry-rb/dry-configurable/compare/v0.8.3...v0.9.0)
|
|
45
|
+
|
|
46
|
+
## 0.8.3 2019-05-29
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- `Configurable#dup` and `Configurable#clone` make a copy of instance-level config so that it doesn't get mutated/shared across instances (flash-gordon)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
[Compare v0.8.2...v0.8.3](https://github.com/dry-rb/dry-configurable/compare/v0.8.2...v0.8.3)
|
|
55
|
+
|
|
56
|
+
## 0.8.2 2019-02-25
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
|
|
61
|
+
- Test interface support for modules ([Neznauy](https://github.com/Neznauy))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
[Compare v0.8.1...v0.8.2](https://github.com/dry-rb/dry-configurable/compare/v0.8.1...v0.8.2)
|
|
65
|
+
|
|
66
|
+
## 0.8.1 2019-02-06
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### Fixed
|
|
70
|
+
|
|
71
|
+
- `.configure` doesn't require a block, this makes the behavior consistent with the previous versions ([flash-gordon](https://github.com/flash-gordon))
|
|
72
|
+
|
|
6
73
|
|
|
7
74
|
[Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-configurable/compare/v0.8.0...v0.8.1)
|
|
8
75
|
|
|
9
|
-
## 0.8.0
|
|
76
|
+
## 0.8.0 2019-02-05
|
|
10
77
|
|
|
11
|
-
## Fixed
|
|
12
78
|
|
|
13
|
-
|
|
79
|
+
### Added
|
|
14
80
|
|
|
15
|
-
|
|
81
|
+
- Support for instance-level configuration landed. For usage, `include` the module instead of extending ([flash-gordon](https://github.com/flash-gordon))
|
|
16
82
|
|
|
17
|
-
* Support for instance-level configuration landed. For usage, `include` the module instead of extending ([flash-gordon](https://github.com/flash-gordon))
|
|
18
83
|
```ruby
|
|
19
84
|
class App
|
|
20
85
|
include Dry::Configurable
|
|
@@ -30,7 +95,8 @@
|
|
|
30
95
|
development.config.database = 'jdbc:sqlite:memory'
|
|
31
96
|
development.finalize!
|
|
32
97
|
```
|
|
33
|
-
|
|
98
|
+
- Config values can be set from a hash with `.update`. Nested settings are supported ([flash-gordon](https://github.com/flash-gordon))
|
|
99
|
+
|
|
34
100
|
```ruby
|
|
35
101
|
class App
|
|
36
102
|
extend Dry::Configurable
|
|
@@ -44,22 +110,25 @@
|
|
|
44
110
|
end
|
|
45
111
|
```
|
|
46
112
|
|
|
47
|
-
|
|
113
|
+
### Fixed
|
|
114
|
+
|
|
115
|
+
- A number of bugs related to inheriting settings from parent class were fixed. Ideally, new behavior will be :100: predictable but if you observe any anomaly, please report ([flash-gordon](https://github.com/flash-gordon))
|
|
116
|
+
|
|
117
|
+
### Changed
|
|
48
118
|
|
|
49
|
-
|
|
119
|
+
- [BREAKING] Minimal supported Ruby version is set to 2.3 ([flash-gordon](https://github.com/flash-gordon))
|
|
50
120
|
|
|
51
121
|
[Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-configurable/compare/v0.7.0...v0.8.0)
|
|
52
122
|
|
|
53
|
-
## 0.7.0
|
|
123
|
+
## 0.7.0 2017-04-25
|
|
54
124
|
|
|
55
|
-
## Added
|
|
56
125
|
|
|
57
|
-
|
|
126
|
+
### Added
|
|
58
127
|
|
|
59
|
-
|
|
128
|
+
- Introduce `Configurable.finalize!` which freezes config and its dependencies ([qcam](https://github.com/qcam))
|
|
60
129
|
|
|
61
|
-
|
|
62
|
-
* Convert nested configs to nested hashes with `Config#to_h` ([saverio-kantox](https://github.com/saverio-kantox))
|
|
63
|
-
* Disallow modification on frozen config ([qcam](https://github.com/qcam))
|
|
130
|
+
### Fixed
|
|
64
131
|
|
|
65
|
-
[
|
|
132
|
+
- Allow for boolean false as default setting value ([yuszuv](https://github.com/yuszuv))
|
|
133
|
+
- Convert nested configs to nested hashes with `Config#to_h` ([saverio-kantox](https://github.com/saverio-kantox))
|
|
134
|
+
- Disallow modification on frozen config ([qcam](https://github.com/qcam))
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
|
-
[gitter]: https://gitter.im/dry-rb/chat
|
|
2
1
|
[gem]: https://rubygems.org/gems/dry-configurable
|
|
3
|
-
[
|
|
4
|
-
[
|
|
2
|
+
[actions]: https://github.com/dry-rb/dry-configurable/actions
|
|
3
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-configurable
|
|
4
|
+
[chat]: https://dry-rb.zulipchat.com
|
|
5
|
+
[inchpages]: http://inch-ci.org/github/dry-rb/dry-configurable
|
|
5
6
|
|
|
6
|
-
# dry-configurable [][chat]
|
|
7
8
|
|
|
8
|
-
[][gem]
|
|
10
|
+
[][actions]
|
|
11
|
+
[][codacy]
|
|
12
|
+
[][codacy]
|
|
13
|
+
[][inchpages]
|
|
13
14
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
Add this line to your application's Gemfile:
|
|
17
|
-
|
|
18
|
-
```ruby
|
|
19
|
-
gem 'dry-configurable'
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
And then execute:
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
$ bundle
|
|
26
|
-
```
|
|
15
|
+
## Links
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
* [User documentation](http://dry-rb.org/gems/dry-configurable)
|
|
18
|
+
* [API documentation](http://rubydoc.info/gems/dry-configurable)
|
|
29
19
|
|
|
30
|
-
|
|
31
|
-
$ gem install dry-configurable
|
|
32
|
-
```
|
|
20
|
+
## Supported Ruby versions
|
|
33
21
|
|
|
34
|
-
|
|
22
|
+
This library officially supports the following Ruby versions:
|
|
35
23
|
|
|
36
|
-
*
|
|
24
|
+
* MRI >= `2.4`
|
|
25
|
+
* jruby >= `9.2`
|
|
37
26
|
|
|
38
27
|
## License
|
|
39
28
|
|
data/dry-configurable.gemspec
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# this file is managed by dry-rb/devtools project
|
|
3
|
+
|
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
|
+
require 'dry/configurable/version'
|
|
2
7
|
|
|
3
8
|
Gem::Specification.new do |spec|
|
|
4
9
|
spec.name = 'dry-configurable'
|
|
5
|
-
spec.
|
|
6
|
-
spec.
|
|
7
|
-
spec.email = ['andyholland1991@aol.com']
|
|
8
|
-
spec.summary = 'A mixin to add configuration functionality to your classes'
|
|
9
|
-
spec.homepage = 'https://github.com/dry-rb/dry-configurable'
|
|
10
|
+
spec.authors = ["Andy Holland"]
|
|
11
|
+
spec.email = ["andyholland1991@aol.com"]
|
|
10
12
|
spec.license = 'MIT'
|
|
13
|
+
spec.version = Dry::Configurable::VERSION.dup
|
|
11
14
|
|
|
12
|
-
spec.
|
|
13
|
-
spec.
|
|
14
|
-
spec.
|
|
15
|
+
spec.summary = "A mixin to add configuration functionality to your classes"
|
|
16
|
+
spec.description = spec.summary
|
|
17
|
+
spec.homepage = 'https://dry-rb.org/gems/dry-configurable'
|
|
18
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-configurable.gemspec", "lib/**/*"]
|
|
19
|
+
spec.bindir = 'bin'
|
|
20
|
+
spec.executables = []
|
|
15
21
|
spec.require_paths = ['lib']
|
|
16
22
|
|
|
17
|
-
spec.
|
|
18
|
-
spec.
|
|
19
|
-
spec.
|
|
23
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
24
|
+
spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-configurable/blob/master/CHANGELOG.md'
|
|
25
|
+
spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-configurable'
|
|
26
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-configurable/issues'
|
|
27
|
+
|
|
28
|
+
spec.required_ruby_version = ">= 2.4.0"
|
|
29
|
+
|
|
30
|
+
# to update dependencies edit project.yml
|
|
31
|
+
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
|
32
|
+
spec.add_runtime_dependency "dry-core", "~> 0.4", ">= 0.4.7"
|
|
33
|
+
spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
|
|
20
34
|
|
|
21
|
-
spec.add_development_dependency
|
|
22
|
-
spec.add_development_dependency
|
|
23
|
-
spec.add_development_dependency
|
|
35
|
+
spec.add_development_dependency "bundler"
|
|
36
|
+
spec.add_development_dependency "rake"
|
|
37
|
+
spec.add_development_dependency "rspec"
|
|
24
38
|
end
|
data/lib/dry-configurable.rb
CHANGED
data/lib/dry/configurable.rb
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require '
|
|
4
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'concurrent/array'
|
|
4
|
+
|
|
5
|
+
require 'dry/configurable/constants'
|
|
6
|
+
require 'dry/configurable/class_methods'
|
|
7
|
+
require 'dry/configurable/instance_methods'
|
|
8
|
+
require 'dry/configurable/config'
|
|
9
|
+
require 'dry/configurable/setting'
|
|
5
10
|
|
|
6
|
-
# A collection of micro-libraries, each intended to encapsulate
|
|
7
|
-
# a common task in Ruby
|
|
8
11
|
module Dry
|
|
9
12
|
# A simple configuration mixin
|
|
10
13
|
#
|
|
@@ -40,135 +43,24 @@ module Dry
|
|
|
40
43
|
#
|
|
41
44
|
# @api public
|
|
42
45
|
module Configurable
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
module ClassMethods
|
|
46
|
-
# @private
|
|
47
|
-
def self.extended(base)
|
|
48
|
-
base.instance_exec do
|
|
49
|
-
@settings = Settings.new
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Add a setting to the configuration
|
|
54
|
-
#
|
|
55
|
-
# @param [Mixed] key
|
|
56
|
-
# The accessor key for the configuration value
|
|
57
|
-
# @param [Mixed] default
|
|
58
|
-
# The default config value
|
|
59
|
-
#
|
|
60
|
-
# @yield
|
|
61
|
-
# If a block is given, it will be evaluated in the context of
|
|
62
|
-
# and new configuration class, and bound as the default value
|
|
63
|
-
#
|
|
64
|
-
# @return [Dry::Configurable::Config]
|
|
65
|
-
#
|
|
66
|
-
# @api public
|
|
67
|
-
def setting(key, value = Undefined, options = Undefined, &block)
|
|
68
|
-
extended = singleton_class < Configurable
|
|
69
|
-
raise_already_defined_config(key) if _settings.config_defined?
|
|
70
|
-
|
|
71
|
-
setting = _settings.add(key, value, options, &block)
|
|
72
|
-
|
|
73
|
-
if setting.reader?
|
|
74
|
-
readers = extended ? singleton_class : self
|
|
75
|
-
readers.send(:define_method, setting.name) { config[setting.name] }
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Return an array of setting names
|
|
80
|
-
#
|
|
81
|
-
# @return [Set]
|
|
82
|
-
#
|
|
83
|
-
# @api public
|
|
84
|
-
def settings
|
|
85
|
-
_settings.names
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# @private no, really...
|
|
89
|
-
def _settings
|
|
90
|
-
@settings
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
private
|
|
94
|
-
|
|
95
|
-
# @private
|
|
96
|
-
def raise_already_defined_config(key)
|
|
97
|
-
raise AlreadyDefinedConfig,
|
|
98
|
-
"Cannot add setting +#{key}+, #{self} is already configured"
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# @private
|
|
102
|
-
def inherited(subclass)
|
|
103
|
-
parent = self
|
|
104
|
-
subclass.instance_exec do
|
|
105
|
-
@settings = parent._settings.dup
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
if singleton_class < Configurable
|
|
109
|
-
parent_config = @config
|
|
110
|
-
subclass.instance_exec do
|
|
111
|
-
@config = _settings.create_config
|
|
112
|
-
@config.define!(parent_config.to_h) if parent_config.defined?
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
super
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
class << self
|
|
121
|
-
# @private
|
|
122
|
-
def extended(base)
|
|
123
|
-
base.extend(ClassMethods)
|
|
124
|
-
base.class_eval do
|
|
125
|
-
@config = _settings.create_config
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# @private
|
|
130
|
-
def included(base)
|
|
131
|
-
base.extend(ClassMethods)
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# @private
|
|
136
|
-
def initialize(*)
|
|
137
|
-
@config = self.class._settings.create_config
|
|
46
|
+
# @api private
|
|
47
|
+
def self.extended(klass)
|
|
138
48
|
super
|
|
49
|
+
klass.extend(ClassMethods)
|
|
139
50
|
end
|
|
140
51
|
|
|
141
|
-
#
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return @config if @config.defined?
|
|
148
|
-
@config.define!
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# Return configuration
|
|
152
|
-
#
|
|
153
|
-
# @yield [Dry::Configuration::Config]
|
|
154
|
-
#
|
|
155
|
-
# @return [Dry::Configurable::Config]
|
|
156
|
-
#
|
|
157
|
-
# @api public
|
|
158
|
-
def configure
|
|
159
|
-
raise FrozenConfig, 'Cannot modify frozen config' if frozen?
|
|
160
|
-
yield(config) if block_given?
|
|
161
|
-
self
|
|
162
|
-
end
|
|
52
|
+
# @api private
|
|
53
|
+
def self.included(klass)
|
|
54
|
+
super
|
|
55
|
+
klass.class_eval do
|
|
56
|
+
extend(ClassMethods)
|
|
57
|
+
include(InstanceMethods)
|
|
163
58
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
def finalize!
|
|
170
|
-
freeze
|
|
171
|
-
config.finalize!
|
|
59
|
+
class << self
|
|
60
|
+
undef :config
|
|
61
|
+
undef :configure
|
|
62
|
+
end
|
|
63
|
+
end
|
|
172
64
|
end
|
|
173
65
|
end
|
|
174
66
|
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'set'
|
|
4
|
+
|
|
5
|
+
require 'dry/configurable/constants'
|
|
6
|
+
require 'dry/configurable/dsl'
|
|
7
|
+
require 'dry/configurable/methods'
|
|
8
|
+
require 'dry/configurable/settings'
|
|
9
|
+
|
|
10
|
+
module Dry
|
|
11
|
+
module Configurable
|
|
12
|
+
module ClassMethods
|
|
13
|
+
include Methods
|
|
14
|
+
|
|
15
|
+
# @api private
|
|
16
|
+
def inherited(klass)
|
|
17
|
+
super
|
|
18
|
+
|
|
19
|
+
parent_settings = (respond_to?(:config) ? config._settings : _settings)
|
|
20
|
+
|
|
21
|
+
klass.instance_variable_set('@_settings', parent_settings)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Add a setting to the configuration
|
|
25
|
+
#
|
|
26
|
+
# @param [Mixed] key
|
|
27
|
+
# The accessor key for the configuration value
|
|
28
|
+
# @param [Mixed] default
|
|
29
|
+
# The default config value
|
|
30
|
+
#
|
|
31
|
+
# @yield
|
|
32
|
+
# If a block is given, it will be evaluated in the context of
|
|
33
|
+
# a new configuration class, and bound as the default value
|
|
34
|
+
#
|
|
35
|
+
# @return [Dry::Configurable::Config]
|
|
36
|
+
#
|
|
37
|
+
# @api public
|
|
38
|
+
def setting(*args, &block)
|
|
39
|
+
setting = __config_dsl__.setting(*args, &block)
|
|
40
|
+
|
|
41
|
+
_settings << setting
|
|
42
|
+
|
|
43
|
+
__config_reader__.define(setting.name) if setting.reader?
|
|
44
|
+
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Return declared settings
|
|
49
|
+
#
|
|
50
|
+
# @return [Set<Symbol>]
|
|
51
|
+
#
|
|
52
|
+
# @api public
|
|
53
|
+
def settings
|
|
54
|
+
@settings ||= Set[*_settings.map(&:name)]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Return declared settings
|
|
58
|
+
#
|
|
59
|
+
# @return [Settings]
|
|
60
|
+
#
|
|
61
|
+
# @api public
|
|
62
|
+
def _settings
|
|
63
|
+
@_settings ||= Settings.new
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Return configuration
|
|
67
|
+
#
|
|
68
|
+
# @return [Config]
|
|
69
|
+
#
|
|
70
|
+
# @api public
|
|
71
|
+
def config
|
|
72
|
+
@config ||= Config.new(_settings)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @api private
|
|
76
|
+
def __config_dsl__
|
|
77
|
+
@dsl ||= DSL.new
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# @api private
|
|
81
|
+
def __config_reader__
|
|
82
|
+
@__config_reader__ ||=
|
|
83
|
+
begin
|
|
84
|
+
reader = Module.new do
|
|
85
|
+
def self.define(name)
|
|
86
|
+
define_method(name) do
|
|
87
|
+
config[name]
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
if included_modules.include?(InstanceMethods)
|
|
93
|
+
include(reader)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
extend(reader)
|
|
97
|
+
|
|
98
|
+
reader
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|