dry-configurable 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/LICENSE +1 -1
- data/lib/dry/configurable.rb +2 -1
- data/lib/dry/configurable/instance_methods.rb +12 -6
- data/lib/dry/configurable/setting.rb +24 -7
- data/lib/dry/configurable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38b75c91290021054add38bdd9e3313f17aa133e219330a9b02a83227abd101c
|
4
|
+
data.tar.gz: 4b808bd3880c35e2e80a702e4577f2b2da35ef2b31667f4314accc3cf0c20470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efdd98ed5f60acf8090296954942f01c21702c29fa60c1edea21e0fbbb185955963b268191cb042ee33cc4651f4350419e7cbc2b7125c36103dce2733d137fa4
|
7
|
+
data.tar.gz: 21d278a4f9f4a90d530145408585c30e004ce2830d5777a408bd9ea83bdfd5cba2ce58f1a1ca46f1212d0e8d5967891a25467f39e59a8af20291cf5ca1beff3f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 0.12.1 2021-02-15
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- Settings may be specified with a `cloneable` option, e.g.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
setting :component_dirs, Configuration::ComponentDirs.new, cloneable: true
|
12
|
+
```
|
13
|
+
|
14
|
+
This change makes it possible to provide “rich” config values that carry their own
|
15
|
+
configuration interface.
|
16
|
+
|
17
|
+
In the above example, `ComponentDirs` could provide its own API for adding component
|
18
|
+
dirs and configuring aspects of their behavior at the same time. By being passed to
|
19
|
+
the setting along with `cloneable: true`, dry-configurable will ensure the setting's
|
20
|
+
values are cloned along with the setting at all the appropriate times.
|
21
|
+
|
22
|
+
A custom cloneable setting value should provide its own `#initialize_copy` (used by
|
23
|
+
`Object#dup`) with the appropriate logic. (@timriley in #102)
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
|
27
|
+
- Only `#initialize` instance method is prepended, leaving the rest of the instance
|
28
|
+
methods to be included as normal again. This allows classes including
|
29
|
+
`Dry::Configurable` to override instance methods with their own methods as required
|
30
|
+
(@adam12 in #103)
|
31
|
+
|
32
|
+
|
33
|
+
[Compare v0.12.0...v0.12.1](https://github.com/dry-rb/dry-configurable/compare/v0.12.0...v0.12.1)
|
34
|
+
|
3
35
|
## 0.12.0 2020-12-26
|
4
36
|
|
5
37
|
|
data/LICENSE
CHANGED
data/lib/dry/configurable.rb
CHANGED
@@ -5,6 +5,18 @@ require 'dry/configurable/methods'
|
|
5
5
|
|
6
6
|
module Dry
|
7
7
|
module Configurable
|
8
|
+
# Initializer method which is prepended when `Dry::Configurable`
|
9
|
+
# is included in a class
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
module Initializer
|
13
|
+
# @api private
|
14
|
+
def initialize(*)
|
15
|
+
@config = Config.new(self.class._settings.dup)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
8
20
|
# Instance-level API when `Dry::Configurable` is included in a class
|
9
21
|
#
|
10
22
|
# @api public
|
@@ -18,12 +30,6 @@ module Dry
|
|
18
30
|
# @api public
|
19
31
|
attr_reader :config
|
20
32
|
|
21
|
-
# @api private
|
22
|
-
def initialize(*)
|
23
|
-
@config = Config.new(self.class._settings.dup)
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
33
|
# Finalize the config and freeze the object
|
28
34
|
#
|
29
35
|
# @api public
|
@@ -15,11 +15,11 @@ module Dry
|
|
15
15
|
class Setting
|
16
16
|
include Dry::Equalizer(:name, :value, :options, inspect: false)
|
17
17
|
|
18
|
-
OPTIONS = %i[input default reader constructor settings].freeze
|
18
|
+
OPTIONS = %i[input default reader constructor cloneable settings].freeze
|
19
19
|
|
20
20
|
DEFAULT_CONSTRUCTOR = -> v { v }.freeze
|
21
21
|
|
22
|
-
|
22
|
+
CLONEABLE_VALUE_TYPES = [Array, Hash, Set, Config].freeze
|
23
23
|
|
24
24
|
# @api private
|
25
25
|
attr_reader :name
|
@@ -54,8 +54,8 @@ module Dry
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# @api private
|
57
|
-
def self.
|
58
|
-
|
57
|
+
def self.cloneable_value?(value)
|
58
|
+
CLONEABLE_VALUE_TYPES.any? { |type| value.is_a?(type) }
|
59
59
|
end
|
60
60
|
|
61
61
|
# @api private
|
@@ -114,15 +114,32 @@ module Dry
|
|
114
114
|
writer_name.equal?(meth)
|
115
115
|
end
|
116
116
|
|
117
|
+
# @api private
|
118
|
+
def cloneable?
|
119
|
+
if options.key?(:cloneable)
|
120
|
+
# Return cloneable option if explicitly set
|
121
|
+
options[:cloneable]
|
122
|
+
else
|
123
|
+
# Otherwise, infer cloneable from any of the input, default, or value
|
124
|
+
Setting.cloneable_value?(input) || Setting.cloneable_value?(default) || (
|
125
|
+
evaluated? && Setting.cloneable_value?(value)
|
126
|
+
)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
117
130
|
private
|
118
131
|
|
119
132
|
# @api private
|
120
133
|
def initialize_copy(source)
|
121
134
|
super
|
122
|
-
|
123
|
-
@default = source.default.dup if Setting.clonable_value?(source.default)
|
124
|
-
@value = source.value.dup if source.evaluated? && Setting.clonable_value?(source.value)
|
135
|
+
|
125
136
|
@options = source.options.dup
|
137
|
+
|
138
|
+
if source.cloneable?
|
139
|
+
@input = source.input.dup
|
140
|
+
@default = source.default.dup
|
141
|
+
@value = source.value.dup if source.evaluated?
|
142
|
+
end
|
126
143
|
end
|
127
144
|
|
128
145
|
# @api private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-configurable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Holland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|