dry-configurable 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +10 -21
  3. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
  4. data/.github/ISSUE_TEMPLATE/---bug-report.md +34 -0
  5. data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
  6. data/.github/workflows/ci.yml +70 -0
  7. data/.github/workflows/docsite.yml +34 -0
  8. data/.github/workflows/sync_configs.yml +30 -0
  9. data/.gitignore +1 -1
  10. data/.rspec +3 -1
  11. data/.rubocop.yml +89 -0
  12. data/CHANGELOG.md +87 -6
  13. data/CODE_OF_CONDUCT.md +13 -0
  14. data/CONTRIBUTING.md +29 -0
  15. data/Gemfile +4 -0
  16. data/LICENSE +1 -1
  17. data/README.md +20 -32
  18. data/docsite/source/index.html.md +55 -0
  19. data/docsite/source/testing.html.md +27 -0
  20. data/dry-configurable.gemspec +10 -4
  21. data/lib/dry/configurable.rb +124 -118
  22. data/lib/dry/configurable/config.rb +136 -43
  23. data/lib/dry/configurable/error.rb +0 -2
  24. data/lib/dry/configurable/setting.rb +46 -0
  25. data/lib/dry/configurable/settings.rb +117 -0
  26. data/lib/dry/configurable/settings/argument_parser.rb +50 -0
  27. data/lib/dry/configurable/test_interface.rb +5 -1
  28. data/lib/dry/configurable/version.rb +1 -1
  29. metadata +56 -38
  30. data/.ruby-version +0 -1
  31. data/.travis.yml +0 -34
  32. data/lib/dry/configurable/argument_parser.rb +0 -91
  33. data/lib/dry/configurable/config/value.rb +0 -27
  34. data/lib/dry/configurable/nested_config.rb +0 -33
  35. data/spec/integration/configurable_spec.rb +0 -25
  36. data/spec/spec_helper.rb +0 -92
  37. data/spec/support/shared_examples/configurable.rb +0 -391
  38. data/spec/unit/dry/configurable/argument_parser_spec.rb +0 -114
  39. data/spec/unit/dry/configurable/config/value_spec.rb +0 -55
  40. data/spec/unit/dry/configurable/config_spec.rb +0 -186
@@ -1,55 +0,0 @@
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 '#initialize' do
9
- it 'coerces string name to symbol' do
10
- config = klass.new('db', value, processor)
11
-
12
- expect(config.name).to eq(:db)
13
- end
14
- end
15
-
16
- describe '#name' do
17
- subject! { config.name }
18
-
19
- it { is_expected.to eq(name) }
20
- end
21
-
22
- describe '#value' do
23
- subject! { config.value }
24
-
25
- context 'when value is not NONE' do
26
- it { is_expected.to eq(value) }
27
- end
28
-
29
- context 'when value is NONE' do
30
- let(:value) { klass::NONE }
31
-
32
- it { is_expected.to be(nil) }
33
- end
34
- end
35
-
36
- describe '#processor' do
37
- subject! { config.processor }
38
-
39
- it { is_expected.to eq(processor) }
40
- end
41
-
42
- describe '#none?' do
43
- subject! { config.none? }
44
-
45
- context 'when value is not NONE' do
46
- it { is_expected.to be(false) }
47
- end
48
-
49
- context 'when value is NONE' do
50
- let(:value) { klass::NONE }
51
-
52
- it { is_expected.to be(true) }
53
- end
54
- end
55
- end
@@ -1,186 +0,0 @@
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 '#finalize!' do
57
- subject!(:dup) { config.finalize! }
58
-
59
- it 'freezes itself and the config' do
60
- expect { config.user = 'whoami' }
61
- .to raise_error(Dry::Configurable::FrozenConfig, 'Cannot modify frozen config')
62
- end
63
- end
64
-
65
- describe '#to_h' do
66
- subject! { config.to_h }
67
-
68
- context 'without nesting' do
69
- it 'returns a config hash' do
70
- is_expected.to eq(
71
- db: 'sqlite:memory',
72
- user: 'root',
73
- pass: nil
74
- )
75
- end
76
- end
77
-
78
- context 'with nesting' do
79
- let(:nested_setting) do
80
- ::Dry::Configurable::NestedConfig.new do
81
- setting(:bar, 'baz') { |v| v }
82
- end.tap(&:create_config)
83
- end
84
- let(:settings) do
85
- [
86
- value_class.new(:db, 'sqlite', ->(v) { "#{v}:memory" }),
87
- value_class.new(:user, 'root', ->(v) { v }),
88
- value_class.new(:pass, none, ->(v) { v }),
89
- value_class.new(:foo, nested_setting, ->(v) { v })
90
- ]
91
- end
92
- it 'returns a config hash' do
93
- is_expected.to eq(
94
- db: 'sqlite:memory',
95
- user: 'root',
96
- pass: nil,
97
- foo: {
98
- bar: 'baz'
99
- }
100
- )
101
- end
102
- end
103
- end
104
-
105
- describe '#to_hash' do
106
- subject! { config.to_hash }
107
-
108
- context 'without nesting' do
109
- it 'returns a config hash' do
110
- is_expected.to eq(
111
- db: 'sqlite:memory',
112
- user: 'root',
113
- pass: nil
114
- )
115
- end
116
- end
117
-
118
- context 'with nesting' do
119
- let(:nested_setting) do
120
- klass.create([value_class.new(:bar, 'baz', ->(v) { v })])
121
- end
122
- let(:settings) do
123
- [
124
- value_class.new(:db, 'sqlite', ->(v) { "#{v}:memory" }),
125
- value_class.new(:user, 'root', ->(v) { v }),
126
- value_class.new(:pass, none, ->(v) { v }),
127
- value_class.new(:foo, nested_setting, ->(v) { v })
128
- ]
129
- end
130
- it 'returns a config hash' do
131
- is_expected.to eq(
132
- db: 'sqlite:memory',
133
- user: 'root',
134
- pass: nil,
135
- foo: {
136
- bar: 'baz'
137
- }
138
- )
139
- end
140
- end
141
- end
142
-
143
- describe '#[]' do
144
- it 'returns given setting' do
145
- expect(config[:db]).to eq('sqlite:memory')
146
- expect(config[:user]).to eq('root')
147
- expect(config[:pass]).to be(nil)
148
- end
149
-
150
- it 'raises an ArgumentError when setting does not exist' do
151
- expect { config[:unknown] }.to raise_error(
152
- ArgumentError, '+unknown+ is not a setting name'
153
- )
154
- end
155
-
156
- it 'accepts setting name as a string' do
157
- expect(config['user']).to eq('root')
158
- end
159
- end
160
-
161
- describe '#[]=' do
162
- it 'sets given setting' do
163
- expect { config[:db] = 'ineedm0ar' }.to change(config, :db)
164
- .from('sqlite:memory')
165
- .to('ineedm0ar:memory')
166
- expect { config[:user] = 'whoami' }.to change(config, :user)
167
- .from('root')
168
- .to('whoami')
169
- expect { config[:pass] = 'h4xz0rz' }.to change(config, :pass)
170
- .from(nil)
171
- .to('h4xz0rz')
172
- end
173
-
174
- it 'raises an ArgumentError when setting does not exist' do
175
- expect { config[:unknown] = 'unknown' }.to raise_error(
176
- ArgumentError, '+unknown+ is not a setting name'
177
- )
178
- end
179
-
180
- it 'accepts setting name as a string' do
181
- expect { config['user'] = 'whoami' }.to change(config, :user)
182
- .from('root')
183
- .to('whoami')
184
- end
185
- end
186
- end