dry-configurable 0.1.7 → 0.3.0
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/.travis.yml +2 -1
- data/Gemfile +0 -2
- data/lib/dry/configurable.rb +29 -8
- data/lib/dry/configurable/config.rb +55 -1
- data/lib/dry/configurable/config/value.rb +25 -0
- data/lib/dry/configurable/version.rb +1 -1
- data/spec/support/shared_examples/configurable.rb +185 -47
- data/spec/unit/dry/configurable/config/value_spec.rb +47 -0
- data/spec/unit/dry/configurable/config_spec.rb +131 -0
- metadata +7 -4
- data/.rubocop.yml +0 -16
- data/.rubocop_todo.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dd64a779f30057a298a82a7f73d6ce3c36909ce
|
4
|
+
data.tar.gz: 0d32b52327b7ceaaff31b8911b52d1f9457e19c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f775f2e95646928bedbfb2ae1e1a57a342473b18e055a76ccfcf7c039e171a5cf8ded036ca96f69f7ea75f922794f6868076f202fc266b0b1c285dc820c7b330
|
7
|
+
data.tar.gz: 0f53eb85546a0a7d1ac4707b7dd68fad429e106a7589c1b272a539c2784fe04d656d9efcac19e940bfc2193d8e2d9962f1329ec113a99c25e29e3152865a110a
|
data/.travis.yml
CHANGED
@@ -9,7 +9,7 @@ rvm:
|
|
9
9
|
- 2.1
|
10
10
|
- 2.2
|
11
11
|
- rbx-2
|
12
|
-
- jruby
|
12
|
+
- jruby-9.0.5.0
|
13
13
|
- ruby-head
|
14
14
|
- jruby-head
|
15
15
|
env:
|
@@ -17,6 +17,7 @@ env:
|
|
17
17
|
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
18
18
|
matrix:
|
19
19
|
allow_failures:
|
20
|
+
- rvm: rbx-2
|
20
21
|
- rvm: ruby-head
|
21
22
|
- rvm: jruby-head
|
22
23
|
notifications:
|
data/Gemfile
CHANGED
data/lib/dry/configurable.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'concurrent'
|
2
2
|
require 'dry/configurable/config'
|
3
|
+
require 'dry/configurable/config/value'
|
3
4
|
require 'dry/configurable/version'
|
4
5
|
|
5
6
|
# A collection of micro-libraries, each intended to encapsulate
|
@@ -29,14 +30,14 @@ module Dry
|
|
29
30
|
# @private
|
30
31
|
def self.extended(base)
|
31
32
|
base.class_eval do
|
32
|
-
@_config_mutex = Mutex.new
|
33
|
-
@_settings = Concurrent::
|
33
|
+
@_config_mutex = ::Mutex.new
|
34
|
+
@_settings = ::Concurrent::Array.new
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
38
|
# @private
|
38
39
|
def inherited(subclass)
|
39
|
-
subclass.instance_variable_set(:@_config_mutex, Mutex.new)
|
40
|
+
subclass.instance_variable_set(:@_config_mutex, ::Mutex.new)
|
40
41
|
subclass.instance_variable_set(:@_settings, @_settings.clone)
|
41
42
|
subclass.instance_variable_set(:@_config, @_config.clone) if defined?(@_config)
|
42
43
|
super
|
@@ -50,7 +51,7 @@ module Dry
|
|
50
51
|
def config
|
51
52
|
return @_config if defined?(@_config)
|
52
53
|
@_config_mutex.synchronize do
|
53
|
-
@_config ||= Config.
|
54
|
+
@_config ||= ::Dry::Configurable::Config.create(_settings) unless _settings.empty?
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
@@ -79,9 +80,29 @@ module Dry
|
|
79
80
|
# @return [Dry::Configurable::Config]
|
80
81
|
#
|
81
82
|
# @api public
|
82
|
-
def setting(key,
|
83
|
-
|
84
|
-
|
83
|
+
def setting(key, value = ::Dry::Configurable::Config::Value::NONE, &block)
|
84
|
+
if block
|
85
|
+
if block.parameters.empty?
|
86
|
+
value = _config_for(&block)
|
87
|
+
else
|
88
|
+
processor = block
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
_settings << ::Dry::Configurable::Config::Value.new(
|
93
|
+
key,
|
94
|
+
value,
|
95
|
+
processor || ::Dry::Configurable::Config::DEFAULT_PROCESSOR
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Return an array of setting names
|
100
|
+
#
|
101
|
+
# @return [Array]
|
102
|
+
#
|
103
|
+
# @api public
|
104
|
+
def settings
|
105
|
+
_settings.map(&:name)
|
85
106
|
end
|
86
107
|
|
87
108
|
# @private no, really...
|
@@ -93,7 +114,7 @@ module Dry
|
|
93
114
|
|
94
115
|
# @private
|
95
116
|
def _config_for(&block)
|
96
|
-
config_klass = Class.new { extend Dry::Configurable }
|
117
|
+
config_klass = ::Class.new { extend ::Dry::Configurable }
|
97
118
|
config_klass.instance_eval(&block)
|
98
119
|
config_klass.config
|
99
120
|
end
|
@@ -1,7 +1,61 @@
|
|
1
1
|
module Dry
|
2
2
|
module Configurable
|
3
3
|
# @private
|
4
|
-
class Config
|
4
|
+
class Config
|
5
|
+
DEFAULT_PROCESSOR = ->(v) { v }.freeze
|
6
|
+
|
7
|
+
def self.create(settings)
|
8
|
+
klass = ::Class.new(self)
|
9
|
+
|
10
|
+
settings.each do |setting|
|
11
|
+
klass.__send__(:define_method, setting.name) do
|
12
|
+
@config[setting.name]
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.__send__(:define_method, "#{setting.name}=") do |value|
|
16
|
+
@config[setting.name] = setting.processor.call(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
klass.new(settings)
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(settings)
|
24
|
+
@config = ::Concurrent::Hash.new
|
25
|
+
|
26
|
+
settings.each do |setting|
|
27
|
+
if setting.none?
|
28
|
+
@config[setting.name] = nil
|
29
|
+
else
|
30
|
+
public_send("#{setting.name}=", setting.value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def dup
|
36
|
+
dup = super
|
37
|
+
dup.instance_variable_set(:@config, @config.dup)
|
38
|
+
dup
|
39
|
+
end
|
40
|
+
|
41
|
+
def clone
|
42
|
+
clone = super
|
43
|
+
clone.instance_variable_set(:@config, @config.clone)
|
44
|
+
clone
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_h
|
48
|
+
@config.each_with_object({}) do |tuple, hash|
|
49
|
+
key, value = tuple
|
50
|
+
|
51
|
+
if value.kind_of?(::Dry::Configurable::Config)
|
52
|
+
hash[key] = value.to_h
|
53
|
+
else
|
54
|
+
hash[key] = value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
alias to_hash to_h
|
5
59
|
end
|
6
60
|
end
|
7
61
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Dry
|
2
|
+
module Configurable
|
3
|
+
class Config
|
4
|
+
# @private
|
5
|
+
class Value
|
6
|
+
# @private
|
7
|
+
NONE = ::Object.new.freeze
|
8
|
+
|
9
|
+
attr_reader :name, :processor
|
10
|
+
|
11
|
+
def initialize(name, value, processor)
|
12
|
+
@name, @value, @processor = name, value, processor
|
13
|
+
end
|
14
|
+
|
15
|
+
def value
|
16
|
+
none? ? nil : @value
|
17
|
+
end
|
18
|
+
|
19
|
+
def none?
|
20
|
+
@value.equal?(::Dry::Configurable::Config::Value::NONE)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,105 +1,243 @@
|
|
1
1
|
RSpec.shared_examples 'a configurable class' do
|
2
2
|
describe Dry::Configurable do
|
3
3
|
describe 'settings' do
|
4
|
-
context 'without
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
context 'without processor option' do
|
5
|
+
context 'without default value' do
|
6
|
+
before do
|
7
|
+
klass.setting :dsn
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
it 'returns nil' do
|
11
|
+
expect(klass.config.dsn).to be(nil)
|
12
|
+
end
|
11
13
|
end
|
12
|
-
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
context 'with default value' do
|
16
|
+
context 'with a nil default value' do
|
17
|
+
before do
|
18
|
+
klass.setting :dsn, nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns the default value' do
|
22
|
+
expect(klass.config.dsn).to be(nil)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with a string default value' do
|
27
|
+
before do
|
28
|
+
klass.setting :dsn, 'sqlite:memory'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns the default value' do
|
32
|
+
expect(klass.config.dsn).to eq('sqlite:memory')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with a hash default value' do
|
37
|
+
before do
|
38
|
+
klass.setting :db_config, {
|
39
|
+
user: 'root',
|
40
|
+
password: ''
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the default value' do
|
45
|
+
expect(klass.config.db_config).to eq(
|
46
|
+
user: 'root',
|
47
|
+
password: ''
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
17
51
|
end
|
18
52
|
|
19
|
-
|
20
|
-
|
53
|
+
context 'nested configuration' do
|
54
|
+
before do
|
55
|
+
klass.setting :database do
|
56
|
+
setting :dsn, 'sqlite:memory'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns the default value' do
|
61
|
+
expect(klass.config.database.dsn).to eq('sqlite:memory')
|
62
|
+
end
|
21
63
|
end
|
22
64
|
end
|
23
65
|
|
24
|
-
context '
|
25
|
-
|
26
|
-
|
27
|
-
setting
|
66
|
+
context 'with processor' do
|
67
|
+
context 'without default value' do
|
68
|
+
before do
|
69
|
+
klass.setting(:dsn) { |dsn| "sqlite:#{dsn}" }
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns nil' do
|
73
|
+
expect(klass.config.dsn).to be(nil)
|
28
74
|
end
|
29
75
|
end
|
30
76
|
|
31
|
-
|
32
|
-
|
77
|
+
context 'with default value' do
|
78
|
+
before do
|
79
|
+
klass.setting(:dsn, 'memory') { |dsn| "sqlite:#{dsn}" }
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns the default value' do
|
83
|
+
expect(klass.config.dsn).to eq('sqlite:memory')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'nested configuration' do
|
88
|
+
before do
|
89
|
+
klass.setting :database do
|
90
|
+
setting(:dsn, 'memory') { |dsn| "sqlite:#{dsn}" }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns the default value' do
|
95
|
+
expect(klass.config.database.dsn).to eq('sqlite:memory')
|
96
|
+
end
|
33
97
|
end
|
34
98
|
end
|
35
99
|
end
|
36
100
|
|
37
101
|
describe 'configuration' do
|
38
102
|
context 'without nesting' do
|
39
|
-
|
40
|
-
|
41
|
-
|
103
|
+
context 'without processor' do
|
104
|
+
before do
|
105
|
+
klass.setting :dsn, 'sqlite:memory'
|
106
|
+
end
|
107
|
+
|
108
|
+
before do
|
109
|
+
klass.configure do |config|
|
110
|
+
config.dsn = 'jdbc:sqlite:memory'
|
111
|
+
end
|
112
|
+
end
|
42
113
|
|
43
|
-
|
44
|
-
|
45
|
-
config.dsn = 'jdbc:sqlite:memory'
|
114
|
+
it 'updates the config value' do
|
115
|
+
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
46
116
|
end
|
47
117
|
end
|
48
118
|
|
49
|
-
|
50
|
-
|
119
|
+
context 'with processor' do
|
120
|
+
before do
|
121
|
+
klass.setting(:dsn, 'sqlite') { |dsn| "#{dsn}:memory"}
|
122
|
+
end
|
123
|
+
|
124
|
+
before do
|
125
|
+
klass.configure do |config|
|
126
|
+
config.dsn = 'jdbc:sqlite'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'updates the config value' do
|
131
|
+
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
132
|
+
end
|
51
133
|
end
|
52
134
|
end
|
53
135
|
|
54
136
|
context 'with nesting' do
|
55
|
-
|
56
|
-
|
57
|
-
setting :
|
137
|
+
context 'without processor' do
|
138
|
+
before do
|
139
|
+
klass.setting :database do
|
140
|
+
setting :dsn, 'sqlite:memory'
|
141
|
+
end
|
142
|
+
|
143
|
+
klass.configure do |config|
|
144
|
+
config.database.dsn = 'jdbc:sqlite:memory'
|
145
|
+
end
|
58
146
|
end
|
59
147
|
|
60
|
-
|
61
|
-
config.database.dsn
|
148
|
+
it 'updates the config value' do
|
149
|
+
expect(klass.config.database.dsn).to eq('jdbc:sqlite:memory')
|
62
150
|
end
|
63
151
|
end
|
64
152
|
|
65
|
-
|
66
|
-
|
153
|
+
context 'with processor' do
|
154
|
+
before do
|
155
|
+
klass.setting :database do
|
156
|
+
setting(:dsn, 'sqlite') { |dsn| "#{dsn}:memory"}
|
157
|
+
end
|
158
|
+
|
159
|
+
klass.configure do |config|
|
160
|
+
config.database.dsn = 'jdbc:sqlite'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'updates the config value' do
|
165
|
+
expect(klass.config.database.dsn).to eq('jdbc:sqlite:memory')
|
166
|
+
end
|
67
167
|
end
|
68
168
|
end
|
69
169
|
|
70
170
|
context 'when inherited' do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
171
|
+
context 'without processor' do
|
172
|
+
before do
|
173
|
+
klass.setting :dsn
|
174
|
+
klass.configure do |config|
|
175
|
+
config.dsn = 'jdbc:sqlite:memory'
|
176
|
+
end
|
75
177
|
end
|
76
|
-
end
|
77
178
|
|
78
|
-
|
179
|
+
subject!(:subclass) { Class.new(klass) }
|
180
|
+
|
181
|
+
it 'retains its configuration' do
|
182
|
+
expect(subclass.config.dsn).to eq('jdbc:sqlite:memory')
|
183
|
+
end
|
79
184
|
|
80
|
-
|
81
|
-
|
185
|
+
context 'when the inherited config is modified' do
|
186
|
+
before do
|
187
|
+
subclass.configure do |config|
|
188
|
+
config.dsn = 'jdbc:sqlite:file'
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'does not modify the original' do
|
193
|
+
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
194
|
+
expect(subclass.config.dsn).to eq('jdbc:sqlite:file')
|
195
|
+
end
|
196
|
+
end
|
82
197
|
end
|
83
198
|
|
84
|
-
context '
|
199
|
+
context 'with processor' do
|
85
200
|
before do
|
86
|
-
|
87
|
-
|
201
|
+
klass.setting(:dsn) { |dsn| "#{dsn}:memory" }
|
202
|
+
klass.configure do |config|
|
203
|
+
config.dsn = 'jdbc:sqlite'
|
88
204
|
end
|
89
205
|
end
|
90
206
|
|
91
|
-
|
92
|
-
|
207
|
+
subject!(:subclass) { Class.new(klass) }
|
208
|
+
|
209
|
+
it 'retains its configuration' do
|
210
|
+
expect(subclass.config.dsn).to eq('jdbc:sqlite:memory')
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when the inherited config is modified' do
|
214
|
+
before do
|
215
|
+
subclass.configure do |config|
|
216
|
+
config.dsn = 'sqlite'
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'does not modify the original' do
|
221
|
+
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
222
|
+
expect(subclass.config.dsn).to eq('sqlite:memory')
|
223
|
+
end
|
93
224
|
end
|
94
225
|
end
|
95
226
|
|
96
227
|
context 'when the inherited settings are modified' do
|
97
228
|
before do
|
229
|
+
klass.setting :dsn
|
230
|
+
klass.configure do |config|
|
231
|
+
config.dsn = 'jdbc:sqlite:memory'
|
232
|
+
end
|
233
|
+
|
98
234
|
subclass.setting :db
|
99
235
|
end
|
100
236
|
|
237
|
+
subject!(:subclass) { Class.new(klass) }
|
238
|
+
|
101
239
|
it 'does not modify the original' do
|
102
|
-
expect(klass.
|
240
|
+
expect(klass.settings).to_not include(:db)
|
103
241
|
end
|
104
242
|
end
|
105
243
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
RSpec.describe Dry::Configurable::Config::Value do
|
2
|
+
let(:klass) { Dry::Configurable::Config::Value }
|
3
|
+
let(:config) { klass.new(name, value, processor) }
|
4
|
+
let(:name) { :db }
|
5
|
+
let(:value) { 'test' }
|
6
|
+
let(:processor) { ->(v) { v }}
|
7
|
+
|
8
|
+
describe '#name' do
|
9
|
+
subject! { config.name }
|
10
|
+
|
11
|
+
it { is_expected.to eq(name) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#value' do
|
15
|
+
subject! { config.value }
|
16
|
+
|
17
|
+
context 'when value is not NONE' do
|
18
|
+
it { is_expected.to eq(value) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when value is NONE' do
|
22
|
+
let(:value) { klass::NONE }
|
23
|
+
|
24
|
+
it { is_expected.to be(nil) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#processor' do
|
29
|
+
subject! { config.processor }
|
30
|
+
|
31
|
+
it { is_expected.to eq(processor) }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#none?' do
|
35
|
+
subject! { config.none? }
|
36
|
+
|
37
|
+
context 'when value is not NONE' do
|
38
|
+
it { is_expected.to be(false) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when value is NONE' do
|
42
|
+
let(:value) { klass::NONE }
|
43
|
+
|
44
|
+
it { is_expected.to be(true) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
RSpec.describe Dry::Configurable::Config do
|
2
|
+
let(:klass) { Dry::Configurable::Config }
|
3
|
+
let(:config) { klass.create(settings) }
|
4
|
+
let(:settings) do
|
5
|
+
[
|
6
|
+
value_class.new(:db, 'sqlite', ->(v) { "#{v}:memory" }),
|
7
|
+
value_class.new(:user, 'root', ->(v) { v }),
|
8
|
+
value_class.new(:pass, none, ->(v) { v })
|
9
|
+
]
|
10
|
+
end
|
11
|
+
let(:value_class) { Dry::Configurable::Config::Value }
|
12
|
+
let(:none) { value_class::NONE }
|
13
|
+
|
14
|
+
describe '.create' do
|
15
|
+
it 'creates a config subclass from the given settings' do
|
16
|
+
expect(config.class).to be < klass
|
17
|
+
|
18
|
+
expect(config.db).to eq('sqlite:memory')
|
19
|
+
expect(config.user).to eq('root')
|
20
|
+
expect(config.pass).to be(nil)
|
21
|
+
|
22
|
+
expect { config.db = 'ineedm0ar' }.to change(config, :db)
|
23
|
+
.from('sqlite:memory')
|
24
|
+
.to('ineedm0ar:memory')
|
25
|
+
expect { config.user = 'whoami' }.to change(config, :user)
|
26
|
+
.from('root')
|
27
|
+
.to('whoami')
|
28
|
+
expect { config.pass = 'h4xz0rz' }.to change(config, :pass)
|
29
|
+
.from(nil)
|
30
|
+
.to('h4xz0rz')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#clone' do
|
35
|
+
subject!(:clone) { config.clone }
|
36
|
+
|
37
|
+
it 'clones and returns the config' do
|
38
|
+
expect(clone.db).to eq(config.db)
|
39
|
+
expect(clone.user).to eq(config.user)
|
40
|
+
expect(clone.pass).to eq(config.pass)
|
41
|
+
is_expected.to_not be(config)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#dup' do
|
46
|
+
subject!(:dup) { config.dup }
|
47
|
+
|
48
|
+
it 'dups and returns the config' do
|
49
|
+
expect(dup.db).to eq(config.db)
|
50
|
+
expect(dup.user).to eq(config.user)
|
51
|
+
expect(dup.pass).to eq(config.pass)
|
52
|
+
is_expected.to_not be(config)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#to_h' do
|
57
|
+
subject! { config.to_h }
|
58
|
+
|
59
|
+
context 'without nesting' do
|
60
|
+
it 'returns a config hash' do
|
61
|
+
is_expected.to eq(
|
62
|
+
db: 'sqlite:memory',
|
63
|
+
user: 'root',
|
64
|
+
pass: nil
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with nesting' do
|
70
|
+
let(:nested_setting) do
|
71
|
+
klass.create([value_class.new(:bar, 'baz', ->(v) { v })])
|
72
|
+
end
|
73
|
+
let(:settings) do
|
74
|
+
[
|
75
|
+
value_class.new(:db, 'sqlite', ->(v) { "#{v}:memory" }),
|
76
|
+
value_class.new(:user, 'root', ->(v) { v }),
|
77
|
+
value_class.new(:pass, none, ->(v) { v }),
|
78
|
+
value_class.new(:foo, nested_setting, ->(v) { v })
|
79
|
+
]
|
80
|
+
end
|
81
|
+
it 'returns a config hash' do
|
82
|
+
is_expected.to eq(
|
83
|
+
db: 'sqlite:memory',
|
84
|
+
user: 'root',
|
85
|
+
pass: nil,
|
86
|
+
foo: {
|
87
|
+
bar: 'baz'
|
88
|
+
}
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#to_hash' do
|
95
|
+
subject! { config.to_hash }
|
96
|
+
|
97
|
+
context 'without nesting' do
|
98
|
+
it 'returns a config hash' do
|
99
|
+
is_expected.to eq(
|
100
|
+
db: 'sqlite:memory',
|
101
|
+
user: 'root',
|
102
|
+
pass: nil
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with nesting' do
|
108
|
+
let(:nested_setting) do
|
109
|
+
klass.create([value_class.new(:bar, 'baz', ->(v) { v })])
|
110
|
+
end
|
111
|
+
let(:settings) do
|
112
|
+
[
|
113
|
+
value_class.new(:db, 'sqlite', ->(v) { "#{v}:memory" }),
|
114
|
+
value_class.new(:user, 'root', ->(v) { v }),
|
115
|
+
value_class.new(:pass, none, ->(v) { v }),
|
116
|
+
value_class.new(:foo, nested_setting, ->(v) { v })
|
117
|
+
]
|
118
|
+
end
|
119
|
+
it 'returns a config hash' do
|
120
|
+
is_expected.to eq(
|
121
|
+
db: 'sqlite:memory',
|
122
|
+
user: 'root',
|
123
|
+
pass: nil,
|
124
|
+
foo: {
|
125
|
+
bar: 'baz'
|
126
|
+
}
|
127
|
+
)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Holland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -76,8 +76,6 @@ files:
|
|
76
76
|
- .codeclimate.yml
|
77
77
|
- .gitignore
|
78
78
|
- .rspec
|
79
|
-
- .rubocop.yml
|
80
|
-
- .rubocop_todo.yml
|
81
79
|
- .ruby-version
|
82
80
|
- .travis.yml
|
83
81
|
- Gemfile
|
@@ -88,11 +86,14 @@ files:
|
|
88
86
|
- lib/dry-configurable.rb
|
89
87
|
- lib/dry/configurable.rb
|
90
88
|
- lib/dry/configurable/config.rb
|
89
|
+
- lib/dry/configurable/config/value.rb
|
91
90
|
- lib/dry/configurable/version.rb
|
92
91
|
- rakelib/rubocop.rake
|
93
92
|
- spec/integration/configurable_spec.rb
|
94
93
|
- spec/spec_helper.rb
|
95
94
|
- spec/support/shared_examples/configurable.rb
|
95
|
+
- spec/unit/dry/configurable/config/value_spec.rb
|
96
|
+
- spec/unit/dry/configurable/config_spec.rb
|
96
97
|
homepage: https://github.com/dryrb/dry-configurable
|
97
98
|
licenses:
|
98
99
|
- MIT
|
@@ -121,3 +122,5 @@ test_files:
|
|
121
122
|
- spec/integration/configurable_spec.rb
|
122
123
|
- spec/spec_helper.rb
|
123
124
|
- spec/support/shared_examples/configurable.rb
|
125
|
+
- spec/unit/dry/configurable/config/value_spec.rb
|
126
|
+
- spec/unit/dry/configurable/config_spec.rb
|
data/.rubocop.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# Generated by `rubocop --auto-gen-config`
|
2
|
-
inherit_from: .rubocop_todo.yml
|
3
|
-
|
4
|
-
Metrics/LineLength:
|
5
|
-
Max: 120
|
6
|
-
|
7
|
-
Style/Documentation:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
Lint/HandleExceptions:
|
11
|
-
Exclude:
|
12
|
-
- rakelib/*.rake
|
13
|
-
|
14
|
-
Style/FileName:
|
15
|
-
Exclude:
|
16
|
-
- lib/dry-configurable.rb
|
data/.rubocop_todo.yml
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-06-10 18:54:14 +0100 using RuboCop version 0.26.0.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|