dry-configurable 0.11.0 → 0.11.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 +12 -1
- data/lib/dry/configurable/class_methods.rb +1 -1
- data/lib/dry/configurable/config.rb +14 -14
- data/lib/dry/configurable/setting.rb +6 -2
- 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: 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,5 +1,16 @@
|
|
1
1
|
## unreleased
|
2
2
|
|
3
|
+
|
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
|
+
|
3
14
|
Complete rewrite of the library while keeping the public API intact. See #78 for a detailed overview.
|
4
15
|
|
5
16
|
### Changed
|
@@ -8,7 +19,7 @@ Complete rewrite of the library while keeping the public API intact. See #78 for
|
|
8
19
|
- (internal) New low-level Setting and Config API (@solnic)
|
9
20
|
- (internal) `config` objects use method_missing now (@solnic)
|
10
21
|
|
11
|
-
[Compare v0.10.0...
|
22
|
+
[Compare v0.10.0...v0.11.0](https://github.com/dry-rb/dry-configurable/compare/v0.10.0...v0.11.0)
|
12
23
|
|
13
24
|
## 0.10.0 2020-01-31
|
14
25
|
|
@@ -16,7 +16,7 @@ module Dry
|
|
16
16
|
def inherited(klass)
|
17
17
|
super
|
18
18
|
|
19
|
-
parent_settings = (respond_to?(:config) ? config.
|
19
|
+
parent_settings = (respond_to?(:config) ? config._settings : _settings)
|
20
20
|
|
21
21
|
klass.instance_variable_set('@_settings', parent_settings)
|
22
22
|
end
|
@@ -16,15 +16,15 @@ module Dry
|
|
16
16
|
include Dry::Equalizer(:values)
|
17
17
|
|
18
18
|
# @api private
|
19
|
-
attr_reader :
|
19
|
+
attr_reader :_settings
|
20
20
|
|
21
21
|
# @api private
|
22
|
-
attr_reader :
|
22
|
+
attr_reader :_resolved
|
23
23
|
|
24
24
|
# @api private
|
25
25
|
def initialize(settings)
|
26
|
-
@
|
27
|
-
@
|
26
|
+
@_settings = settings.dup
|
27
|
+
@_resolved = Concurrent::Map.new
|
28
28
|
end
|
29
29
|
|
30
30
|
# Get config value by a key
|
@@ -33,9 +33,9 @@ module Dry
|
|
33
33
|
#
|
34
34
|
# @return Config value
|
35
35
|
def [](name)
|
36
|
-
raise ArgumentError, "+#{name}+ is not a setting name" unless
|
36
|
+
raise ArgumentError, "+#{name}+ is not a setting name" unless _settings.key?(name)
|
37
37
|
|
38
|
-
|
38
|
+
_settings[name].value
|
39
39
|
end
|
40
40
|
|
41
41
|
# Set config value.
|
@@ -71,7 +71,7 @@ module Dry
|
|
71
71
|
#
|
72
72
|
# @api public
|
73
73
|
def values
|
74
|
-
|
74
|
+
_settings
|
75
75
|
.map { |setting| [setting.name, setting.value] }
|
76
76
|
.map { |key, value| [key, value.is_a?(self.class) ? value.to_h : value] }
|
77
77
|
.to_h
|
@@ -81,32 +81,32 @@ module Dry
|
|
81
81
|
|
82
82
|
# @api private
|
83
83
|
def finalize!
|
84
|
-
|
84
|
+
_settings.freeze
|
85
85
|
freeze
|
86
86
|
end
|
87
87
|
|
88
88
|
# @api private
|
89
89
|
def pristine
|
90
|
-
self.class.new(
|
90
|
+
self.class.new(_settings.pristine)
|
91
91
|
end
|
92
92
|
|
93
93
|
# @api private
|
94
94
|
def respond_to_missing?(meth, include_private = false)
|
95
|
-
super ||
|
95
|
+
super || _settings.key?(resolve(meth))
|
96
96
|
end
|
97
97
|
|
98
98
|
private
|
99
99
|
|
100
100
|
# @api private
|
101
101
|
def method_missing(meth, *args)
|
102
|
-
setting =
|
102
|
+
setting = _settings[resolve(meth)]
|
103
103
|
|
104
104
|
super unless setting
|
105
105
|
|
106
106
|
if setting.writer?(meth)
|
107
107
|
raise FrozenConfig, 'Cannot modify frozen config' if frozen?
|
108
108
|
|
109
|
-
|
109
|
+
_settings << setting.with(input: args[0])
|
110
110
|
else
|
111
111
|
setting.value
|
112
112
|
end
|
@@ -114,13 +114,13 @@ module Dry
|
|
114
114
|
|
115
115
|
# @api private
|
116
116
|
def resolve(meth)
|
117
|
-
|
117
|
+
_resolved.fetch(meth) { _resolved[meth] = meth.to_s.tr('=', '').to_sym }
|
118
118
|
end
|
119
119
|
|
120
120
|
# @api private
|
121
121
|
def initialize_copy(source)
|
122
122
|
super
|
123
|
-
@
|
123
|
+
@_settings = source._settings.dup
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
@@ -63,7 +63,11 @@ module Dry
|
|
63
63
|
@input = input.equal?(Undefined) ? default : input
|
64
64
|
@default = default
|
65
65
|
@options = options
|
66
|
-
|
66
|
+
end
|
67
|
+
|
68
|
+
# @api private
|
69
|
+
def value
|
70
|
+
@value ||= evaluate
|
67
71
|
end
|
68
72
|
|
69
73
|
# @api private
|
@@ -111,7 +115,7 @@ module Dry
|
|
111
115
|
end
|
112
116
|
|
113
117
|
# @api private
|
114
|
-
def
|
118
|
+
def evaluate
|
115
119
|
@value = constructor[input.equal?(Undefined) ? nil : input]
|
116
120
|
end
|
117
121
|
end
|
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.11.
|
4
|
+
version: 0.11.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: 2020-02-
|
11
|
+
date: 2020-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|