dry-configurable 0.11.6 → 1.0.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 +187 -2
- data/LICENSE +1 -1
- data/README.md +5 -4
- data/dry-configurable.gemspec +16 -16
- data/lib/dry/configurable/class_methods.rb +40 -31
- data/lib/dry/configurable/compiler.rb +5 -12
- data/lib/dry/configurable/config.rb +133 -47
- data/lib/dry/configurable/constants.rb +0 -2
- data/lib/dry/configurable/dsl.rb +35 -23
- data/lib/dry/configurable/errors.rb +3 -2
- data/lib/dry/configurable/extension.rb +48 -0
- data/lib/dry/configurable/instance_methods.rb +20 -12
- data/lib/dry/configurable/methods.rb +3 -7
- data/lib/dry/configurable/setting.rb +44 -91
- data/lib/dry/configurable/settings.rb +30 -37
- data/lib/dry/configurable/test_interface.rb +1 -1
- data/lib/dry/configurable/version.rb +1 -1
- data/lib/dry/configurable.rb +27 -19
- data/lib/dry-configurable.rb +1 -1
- metadata +15 -29
- data/lib/dry/configurable/dsl/args.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9dc2db3ddad9ce63a4129b8792a0d0fc26695169015c33721d49a153a3972bc
|
4
|
+
data.tar.gz: 67b7b36444ac64bd06bd0800e5ac74aaced969aa74b31bd686f8e7ecbc4b6b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32317f78da754f348e1b4cda2817d81d48ca0cc32fb2b8cedff62d499589063d8c7b3f54917114f37412007593ca44c6d33d99c87ab44d5fa3dcbd13684c3bb1
|
7
|
+
data.tar.gz: 373c4b8e6d9fcd015acae6b5aebaa82a307a57a1a541480a7c2887f6bba2c24c80992c9f1352e9a97caea3f21e857ebb23a94a0c43f8598332425f942e49794f
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,189 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## 1.0.1 2022-11-16
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- Renamed `@config` and `@_settings` internal instance variables to `@__config__` and `@__settings__` in order to avoid clashes with user-defined instance variables (#159 by @timriley)
|
9
|
+
|
10
|
+
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-configurable/compare/v1.0.0...v1.0.1)
|
11
|
+
|
12
|
+
## 1.0.0 2022-11-04
|
13
|
+
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Dependency on `dry-core` was updated to ~> 1.0 (@solnic)
|
18
|
+
|
19
|
+
[Compare v0.16.1...v1.0.0](https://github.com/dry-rb/dry-configurable/compare/v0.16.1...v1.0.0)
|
20
|
+
|
21
|
+
## 0.16.1 2022-10-13
|
22
|
+
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
|
26
|
+
- Restored performance of config value reads (direct reader methods as well as aggregate methods like `#values` and `#to_h`) to pre-0.16.0 levels (#149 by @timriley)
|
27
|
+
|
28
|
+
[Compare v0.16.0...v0.16.1](https://github.com/dry-rb/dry-configurable/compare/v0.16.0...v0.16.1)
|
29
|
+
|
30
|
+
## 0.16.0 2022-10-08
|
31
|
+
|
32
|
+
|
33
|
+
### Added
|
34
|
+
|
35
|
+
- Support for custom config classes via `config_class:` option (#136 by @solnic)
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
extend Dry::Configurable(config_class: MyConfig)
|
39
|
+
```
|
40
|
+
|
41
|
+
Your config class should inherit from `Dry::Configurable::Config`.
|
42
|
+
- Return `Dry::Core::Constants::Undefined` (instead of nil) as the value for non-configured settings via a `default_undefined: true` option (#141 by @timriley)
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
extend Dry::Configurable(default_undefined: true)
|
46
|
+
```
|
47
|
+
|
48
|
+
You must opt into this feature via the `default_undefined: true` option. Non-configured setting values are still `nil` by default.
|
49
|
+
|
50
|
+
### Fixed
|
51
|
+
|
52
|
+
- Remove exec bit from version.rb (#139 by @Fryguy)
|
53
|
+
|
54
|
+
### Changed
|
55
|
+
|
56
|
+
- Improve memory usage by separating setting definitions from config values (#138 by @timriley)
|
57
|
+
|
58
|
+
Your usage of dry-configurable may be impacted if you have been accessing objects from `_settings` or the internals of `Dry::Configurable::Config`. `_settings` now returns `Dry::Configurable::Setting` instances, which contain only the details from the setting's definition. Setting _values_ remain in `Dry::Configurable::Config`.
|
59
|
+
- Use Zeitwerk to speed up load time (#135 by @solnic)
|
60
|
+
|
61
|
+
[Compare v0.15.0...v0.16.0](https://github.com/dry-rb/dry-configurable/compare/v0.15.0...v0.16.0)
|
62
|
+
|
63
|
+
## 0.15.0 2022-04-21
|
64
|
+
|
65
|
+
|
66
|
+
### Changed
|
67
|
+
|
68
|
+
- The `finalize!` method (as class or instance method, depending on whether you extend or include `Dry::Configurable` respectively) now accepts a boolean `freeze_values:` argument, which if true, will recursively freeze all config values in addition to the `config` itself. (#105 by @ojab)
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
class MyConfigurable
|
72
|
+
include Dry::Configurable
|
73
|
+
|
74
|
+
setting :db, default: "postgre"
|
75
|
+
end
|
76
|
+
|
77
|
+
my_obj = MyConfigurable.new
|
78
|
+
my_obj.finalize!(freeze_values: true)
|
79
|
+
my_obj.config.db << "sql" # Will raise FrozenError
|
80
|
+
```
|
81
|
+
- `Dry::Configurable::Config#update` will set hashes as values for non-nested settings (#131 by @ojab)
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class MyConfigurable
|
85
|
+
extend Dry::Configurable
|
86
|
+
|
87
|
+
setting :sslcert, constructor: ->(v) { v&.values_at(:pem, :pass)&.join }
|
88
|
+
end
|
89
|
+
|
90
|
+
MyConfigurable.config.update(sslcert: {pem: "cert", pass: "qwerty"})
|
91
|
+
MyConfigurable.config.sslcert # => "certqwerty"
|
92
|
+
```
|
93
|
+
- `Dry::Configurable::Config#update` will accept any values implicitly convertible to hash via `#to_hash` (#133 by @timriley)
|
94
|
+
|
95
|
+
[Compare v0.14.0...v0.15.0](https://github.com/dry-rb/dry-configurable/compare/v0.14.0...v0.15.0)
|
96
|
+
|
97
|
+
## 0.14.0 2022-01-14
|
98
|
+
|
99
|
+
|
100
|
+
### Changed
|
101
|
+
|
102
|
+
- Settings defined after an access to `config` will still be made available on that `config`. (#130 by @timriley)
|
103
|
+
- Cloneable settings are cloned immediately upon assignment. (#130 by @timriley)
|
104
|
+
- Changes to config values in parent classes after subclasses have already been created will not be propogated to those subclasses. Subclasses created _after_ config values have been changed in the parent _will_ receive those config values. (#130 by @timriley)
|
105
|
+
|
106
|
+
[Compare v0.13.0...v0.14.0](https://github.com/dry-rb/dry-configurable/compare/v0.13.0...v0.14.0)
|
107
|
+
|
108
|
+
## 0.13.0 2021-09-12
|
109
|
+
|
110
|
+
|
111
|
+
### Added
|
112
|
+
|
113
|
+
- Added flags to determine whether to warn on the API usage deprecated in this release (see "Changed" section below). Set these to `false` to suppress the warnings. (#124 by @timriley)
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
Dry::Configurable.warn_on_setting_constructor_block false
|
117
|
+
Dry::Configurable.warn_on_setting_positional_default false
|
118
|
+
```
|
119
|
+
|
120
|
+
### Fixed
|
121
|
+
|
122
|
+
- Fixed `ArgumentError` for classes including `Dry::Configurable` whose `initializer` has required kwargs. (#113 by @timriley)
|
123
|
+
|
124
|
+
### Changed
|
125
|
+
|
126
|
+
- Deprecated the setting constructor provided as a block. Provide it via the `constructor:` keyword argument instead. (#111 by @waiting-for-dev & @timriley)
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
setting :path, constructor: -> path { Pathname(path) }
|
130
|
+
```
|
131
|
+
- Deprecated the setting default provided as the second positional argument. Provide it via the `default:` keyword argument instead. (#112 and #121 by @waiting-for-dev & @timriley)
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
setting :path, default: "some/default/path"
|
135
|
+
```
|
136
|
+
- [BREAKING] Removed implicit `to_hash` conversion from `Config`. (#114 by @timriley)
|
137
|
+
|
138
|
+
[Compare v0.12.1...v0.13.0](https://github.com/dry-rb/dry-configurable/compare/v0.12.1...v0.13.0)
|
139
|
+
|
140
|
+
## 0.12.1 2021-02-15
|
141
|
+
|
142
|
+
|
143
|
+
### Added
|
144
|
+
|
145
|
+
- Settings may be specified with a `cloneable` option, e.g.
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
setting :component_dirs, Configuration::ComponentDirs.new, cloneable: true
|
149
|
+
```
|
150
|
+
|
151
|
+
This change makes it possible to provide “rich” config values that carry their own
|
152
|
+
configuration interface.
|
153
|
+
|
154
|
+
In the above example, `ComponentDirs` could provide its own API for adding component
|
155
|
+
dirs and configuring aspects of their behavior at the same time. By being passed to
|
156
|
+
the setting along with `cloneable: true`, dry-configurable will ensure the setting's
|
157
|
+
values are cloned along with the setting at all the appropriate times.
|
158
|
+
|
159
|
+
A custom cloneable setting value should provide its own `#initialize_copy` (used by
|
160
|
+
`Object#dup`) with the appropriate logic. (@timriley in #102)
|
161
|
+
|
162
|
+
### Fixed
|
163
|
+
|
164
|
+
- Only `#initialize` instance method is prepended, leaving the rest of the instance
|
165
|
+
methods to be included as normal again. This allows classes including
|
166
|
+
`Dry::Configurable` to override instance methods with their own methods as required
|
167
|
+
(@adam12 in #103)
|
168
|
+
|
169
|
+
|
170
|
+
[Compare v0.12.0...v0.12.1](https://github.com/dry-rb/dry-configurable/compare/v0.12.0...v0.12.1)
|
171
|
+
|
172
|
+
## 0.12.0 2020-12-26
|
173
|
+
|
174
|
+
|
175
|
+
### Fixed
|
176
|
+
|
177
|
+
- Setting values provided by defaults and/or pre-processor blocks are no longer accidentally memoized across instances of classes including Dry::Configurable (#99) (@timriley & @esparta)
|
178
|
+
|
179
|
+
### Changed
|
180
|
+
|
181
|
+
- Instance behavior is now prepended, so that if you have your own `initialize`, calling `super` is no longer required (see #98 for more details) (@zabolotnov87)
|
182
|
+
- Switched to equalizer from dry-core (@solnic)
|
183
|
+
|
184
|
+
[Compare v0.11.6...v0.12.0](https://github.com/dry-rb/dry-configurable/compare/v0.11.6...v0.12.0)
|
185
|
+
|
186
|
+
## 0.11.6 2020-06-22
|
2
187
|
|
3
188
|
|
4
189
|
### Changed
|
@@ -6,7 +191,7 @@
|
|
6
191
|
- A meaningful error is raised when the extension is included more than once (issue #89 fixed via #94) (@landongrindheim)
|
7
192
|
- Evaluate setting input immediately when input is provided. This allows for earlier feedback from constructors designed to raise errors on invalid input (#95) (@timriley)
|
8
193
|
|
9
|
-
[Compare v0.11.5...
|
194
|
+
[Compare v0.11.5...v0.11.6](https://github.com/dry-rb/dry-configurable/compare/v0.11.5...v0.11.6)
|
10
195
|
|
11
196
|
## 0.11.5 2020-03-23
|
12
197
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
1
2
|
[gem]: https://rubygems.org/gems/dry-configurable
|
2
3
|
[actions]: https://github.com/dry-rb/dry-configurable/actions
|
3
4
|
[codacy]: https://www.codacy.com/gh/dry-rb/dry-configurable
|
@@ -10,19 +11,19 @@
|
|
10
11
|
[][actions]
|
11
12
|
[][codacy]
|
12
13
|
[][codacy]
|
13
|
-
[][inchpages]
|
14
15
|
|
15
16
|
## Links
|
16
17
|
|
17
|
-
* [User documentation](
|
18
|
+
* [User documentation](https://dry-rb.org/gems/dry-configurable)
|
18
19
|
* [API documentation](http://rubydoc.info/gems/dry-configurable)
|
19
20
|
|
20
21
|
## Supported Ruby versions
|
21
22
|
|
22
23
|
This library officially supports the following Ruby versions:
|
23
24
|
|
24
|
-
* MRI
|
25
|
-
* jruby
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
26
27
|
|
27
28
|
## License
|
28
29
|
|
data/dry-configurable.gemspec
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# this file is managed by dry-rb/devtools project
|
3
2
|
|
4
|
-
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
4
|
+
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
5
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require
|
7
|
+
require "dry/configurable/version"
|
7
8
|
|
8
9
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
10
|
+
spec.name = "dry-configurable"
|
10
11
|
spec.authors = ["Andy Holland"]
|
11
12
|
spec.email = ["andyholland1991@aol.com"]
|
12
|
-
spec.license =
|
13
|
+
spec.license = "MIT"
|
13
14
|
spec.version = Dry::Configurable::VERSION.dup
|
14
15
|
|
15
16
|
spec.summary = "A mixin to add configuration functionality to your classes"
|
16
17
|
spec.description = spec.summary
|
17
|
-
spec.homepage =
|
18
|
+
spec.homepage = "https://dry-rb.org/gems/dry-configurable"
|
18
19
|
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-configurable.gemspec", "lib/**/*"]
|
19
|
-
spec.bindir =
|
20
|
+
spec.bindir = "bin"
|
20
21
|
spec.executables = []
|
21
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ["lib"]
|
22
23
|
|
23
|
-
spec.metadata[
|
24
|
-
spec.metadata[
|
25
|
-
spec.metadata[
|
26
|
-
spec.metadata[
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-configurable/blob/main/CHANGELOG.md"
|
26
|
+
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-configurable"
|
27
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-configurable/issues"
|
27
28
|
|
28
|
-
spec.required_ruby_version = ">= 2.
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
29
30
|
|
30
31
|
# to update dependencies edit project.yml
|
31
|
-
spec.add_runtime_dependency "
|
32
|
-
spec.add_runtime_dependency "
|
33
|
-
spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
|
32
|
+
spec.add_runtime_dependency "dry-core", "~> 1.0", "< 2"
|
33
|
+
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
34
34
|
|
35
35
|
spec.add_development_dependency "bundler"
|
36
36
|
spec.add_development_dependency "rake"
|
@@ -1,11 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
require 'dry/configurable/constants'
|
6
|
-
require 'dry/configurable/dsl'
|
7
|
-
require 'dry/configurable/methods'
|
8
|
-
require 'dry/configurable/settings'
|
3
|
+
require "set"
|
9
4
|
|
10
5
|
module Dry
|
11
6
|
module Configurable
|
@@ -13,54 +8,55 @@ module Dry
|
|
13
8
|
include Methods
|
14
9
|
|
15
10
|
# @api private
|
16
|
-
def inherited(
|
11
|
+
def inherited(subclass)
|
17
12
|
super
|
18
13
|
|
19
|
-
|
14
|
+
subclass.instance_variable_set(:@__config_extension__, __config_extension__)
|
15
|
+
|
16
|
+
new_settings = settings.dup
|
17
|
+
subclass.instance_variable_set(:@__settings__, new_settings)
|
20
18
|
|
21
|
-
|
19
|
+
# Only classes **extending** Dry::Configurable have class-level config. When
|
20
|
+
# Dry::Configurable is **included**, the class-level config method is undefined because it
|
21
|
+
# resides at the instance-level instead (see `Configurable.included`).
|
22
|
+
if respond_to?(:config)
|
23
|
+
subclass.instance_variable_set(:@__config__, config.dup_for_settings(new_settings))
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
# Add a setting to the configuration
|
25
28
|
#
|
26
|
-
# @param [Mixed]
|
29
|
+
# @param [Mixed] name
|
27
30
|
# The accessor key for the configuration value
|
28
31
|
# @param [Mixed] default
|
29
|
-
#
|
30
|
-
#
|
32
|
+
# Default value for the setting
|
33
|
+
# @param [#call] constructor
|
34
|
+
# Transformation given value will go through
|
35
|
+
# @param [Boolean] reader
|
36
|
+
# Whether a reader accessor must be created
|
31
37
|
# @yield
|
32
|
-
#
|
33
|
-
# a new configuration class, and bound as the default value
|
38
|
+
# A block can be given to add nested settings.
|
34
39
|
#
|
35
40
|
# @return [Dry::Configurable::Config]
|
36
41
|
#
|
37
42
|
# @api public
|
38
|
-
def setting(*args, &block)
|
39
|
-
setting = __config_dsl__.setting(*args, &block)
|
43
|
+
def setting(*args, **options, &block)
|
44
|
+
setting = __config_dsl__.setting(*args, **options, &block)
|
40
45
|
|
41
|
-
|
46
|
+
settings << setting
|
42
47
|
|
43
48
|
__config_reader__.define(setting.name) if setting.reader?
|
44
49
|
|
45
50
|
self
|
46
51
|
end
|
47
52
|
|
48
|
-
#
|
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
|
53
|
+
# Returns the defined settings for the class.
|
58
54
|
#
|
59
55
|
# @return [Settings]
|
60
56
|
#
|
61
57
|
# @api public
|
62
|
-
def
|
63
|
-
@
|
58
|
+
def settings
|
59
|
+
@__settings__ ||= Settings.new
|
64
60
|
end
|
65
61
|
|
66
62
|
# Return configuration
|
@@ -69,12 +65,25 @@ module Dry
|
|
69
65
|
#
|
70
66
|
# @api public
|
71
67
|
def config
|
72
|
-
@
|
68
|
+
@__config__ ||= __config_build__
|
69
|
+
end
|
70
|
+
|
71
|
+
# @api private
|
72
|
+
def __config_build__(settings = self.settings)
|
73
|
+
__config_extension__.config_class.new(settings)
|
74
|
+
end
|
75
|
+
|
76
|
+
# @api private
|
77
|
+
def __config_extension__
|
78
|
+
@__config_extension__
|
73
79
|
end
|
74
80
|
|
75
81
|
# @api private
|
76
82
|
def __config_dsl__
|
77
|
-
@
|
83
|
+
@__config_dsl__ ||= DSL.new(
|
84
|
+
config_class: __config_extension__.config_class,
|
85
|
+
default_undefined: __config_extension__.default_undefined
|
86
|
+
)
|
78
87
|
end
|
79
88
|
|
80
89
|
# @api private
|
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dry/configurable/setting'
|
4
|
-
require 'dry/configurable/settings'
|
5
|
-
|
6
3
|
module Dry
|
7
4
|
module Configurable
|
8
5
|
# Setting compiler used internally by the DSL
|
@@ -23,22 +20,18 @@ module Dry
|
|
23
20
|
public_send(:"visit_#{type}", rest)
|
24
21
|
end
|
25
22
|
|
26
|
-
# @api private
|
27
|
-
def visit_constructor(node)
|
28
|
-
setting, constructor = node
|
29
|
-
visit(setting).with(constructor: constructor)
|
30
|
-
end
|
31
|
-
|
32
23
|
# @api private
|
33
24
|
def visit_setting(node)
|
34
|
-
name,
|
35
|
-
Setting.new(name, **opts
|
25
|
+
name, opts = node
|
26
|
+
Setting.new(name, **opts)
|
36
27
|
end
|
37
28
|
|
38
29
|
# @api private
|
39
30
|
def visit_nested(node)
|
40
31
|
parent, children = node
|
41
|
-
|
32
|
+
name, opts = parent[1]
|
33
|
+
|
34
|
+
Setting.new(name, **opts, children: Settings.new(call(children)))
|
42
35
|
end
|
43
36
|
end
|
44
37
|
end
|