complex_config 0.14.0 → 0.14.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/README.md +3 -1
- data/VERSION +1 -1
- data/complex_config.gemspec +8 -8
- data/lib/complex_config/encryption.rb +3 -1
- data/lib/complex_config/settings.rb +5 -0
- data/lib/complex_config/version.rb +1 -1
- data/spec/complex_config/encryption_spec.rb +8 -0
- data/spec/complex_config/plugins_spec.rb +3 -3
- data/spec/complex_config/provider_spec.rb +83 -87
- data/spec/complex_config/settings_spec.rb +14 -6
- metadata +3 -4
- data/TODO.md +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c28053b61dff2ae48b2da22e7bd5e8f2bcc80f48fdeaf490c9a2a607d4e876c9
|
4
|
+
data.tar.gz: cadf63913aeebf969f0f99d76a6be2e6c06cad5304f40699b96dce0fcd77e8f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e00cb460bb319128e56fa2ea8607bdaa93a16bf64c279d2480d417633688e80eb8fc6e2ea905345862dbc8ad2174ef6d30b218742addb055108b9933c07142ee
|
7
|
+
data.tar.gz: 49a16f1422acee6f938c09e4de0fee07861b765c1ada576ecad07bb957f35fc0d6d35119287717af7ad8c4936de874d15a3c661a5069212af763dbfcc7022102
|
data/README.md
CHANGED
@@ -143,7 +143,9 @@ Here is the `ComplexConfig::Plugins::MONEY` plugin for example:
|
|
143
143
|
end
|
144
144
|
|
145
145
|
## Changes
|
146
|
-
|
146
|
+
* 2018-07-06 Release 0.14.0
|
147
|
+
* Better support for rails encryption
|
148
|
+
* Adds `complex_config` executable.
|
147
149
|
* 2018-02-23 Release 0.13.3
|
148
150
|
Change evaluation order of key sources
|
149
151
|
* 2018-02-23 Release 0.13.2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.14.
|
1
|
+
0.14.1
|
data/complex_config.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: complex_config 0.14.
|
2
|
+
# stub: complex_config 0.14.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "complex_config".freeze
|
6
|
-
s.version = "0.14.
|
6
|
+
s.version = "0.14.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2018-
|
11
|
+
s.date = "2018-12-07"
|
12
12
|
s.description = "This library allows you to access configuration files via a simple interface".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.executables = ["complex_config".freeze]
|
15
15
|
s.extra_rdoc_files = ["README.md".freeze, "lib/complex_config.rb".freeze, "lib/complex_config/config.rb".freeze, "lib/complex_config/encryption.rb".freeze, "lib/complex_config/errors.rb".freeze, "lib/complex_config/key_source.rb".freeze, "lib/complex_config/plugins.rb".freeze, "lib/complex_config/plugins/enable.rb".freeze, "lib/complex_config/plugins/money.rb".freeze, "lib/complex_config/plugins/uri.rb".freeze, "lib/complex_config/provider.rb".freeze, "lib/complex_config/provider/shortcuts.rb".freeze, "lib/complex_config/proxy.rb".freeze, "lib/complex_config/railtie.rb".freeze, "lib/complex_config/rude.rb".freeze, "lib/complex_config/settings.rb".freeze, "lib/complex_config/shortcuts.rb".freeze, "lib/complex_config/version.rb".freeze]
|
16
|
-
s.files = [".gitignore".freeze, ".rspec".freeze, ".travis.yml".freeze, ".utilsrc".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "
|
16
|
+
s.files = [".gitignore".freeze, ".rspec".freeze, ".travis.yml".freeze, ".utilsrc".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/complex_config".freeze, "complex_config.gemspec".freeze, "config/products.yml".freeze, "lib/complex_config.rb".freeze, "lib/complex_config/config.rb".freeze, "lib/complex_config/encryption.rb".freeze, "lib/complex_config/errors.rb".freeze, "lib/complex_config/key_source.rb".freeze, "lib/complex_config/plugins.rb".freeze, "lib/complex_config/plugins/enable.rb".freeze, "lib/complex_config/plugins/money.rb".freeze, "lib/complex_config/plugins/uri.rb".freeze, "lib/complex_config/provider.rb".freeze, "lib/complex_config/provider/shortcuts.rb".freeze, "lib/complex_config/proxy.rb".freeze, "lib/complex_config/railtie.rb".freeze, "lib/complex_config/rude.rb".freeze, "lib/complex_config/settings.rb".freeze, "lib/complex_config/shortcuts.rb".freeze, "lib/complex_config/version.rb".freeze, "spec/complex_config/config_spec.rb".freeze, "spec/complex_config/encryption_spec.rb".freeze, "spec/complex_config/key_source_spec.rb".freeze, "spec/complex_config/plugins_spec.rb".freeze, "spec/complex_config/provider_spec.rb".freeze, "spec/complex_config/settings_spec.rb".freeze, "spec/complex_config/shortcuts_spec.rb".freeze, "spec/config/broken_config.yml".freeze, "spec/config/config.yml".freeze, "spec/config/master.key".freeze, "spec/config/with-key-file.yml.enc".freeze, "spec/config/with-key-file.yml.key".freeze, "spec/config/without-key-file.yml.enc".freeze, "spec/spec_helper.rb".freeze]
|
17
17
|
s.homepage = "https://github.com/flori/complex_config".freeze
|
18
18
|
s.licenses = ["Apache-2.0".freeze]
|
19
19
|
s.rdoc_options = ["--title".freeze, "ComplexConfig -- configuration library".freeze, "--main".freeze, "README.md".freeze]
|
20
|
-
s.rubygems_version = "2.7.
|
20
|
+
s.rubygems_version = "2.7.8".freeze
|
21
21
|
s.summary = "configuration library".freeze
|
22
22
|
s.test_files = ["spec/complex_config/config_spec.rb".freeze, "spec/complex_config/encryption_spec.rb".freeze, "spec/complex_config/key_source_spec.rb".freeze, "spec/complex_config/plugins_spec.rb".freeze, "spec/complex_config/provider_spec.rb".freeze, "spec/complex_config/settings_spec.rb".freeze, "spec/complex_config/shortcuts_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
23
23
|
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_development_dependency(%q<monetize>.freeze, [">= 0"])
|
33
33
|
s.add_runtime_dependency(%q<json>.freeze, [">= 0"])
|
34
34
|
s.add_runtime_dependency(%q<tins>.freeze, [">= 0"])
|
35
|
-
s.add_runtime_dependency(%q<mize>.freeze, ["
|
35
|
+
s.add_runtime_dependency(%q<mize>.freeze, ["~> 0.3", ">= 0.3.4"])
|
36
36
|
else
|
37
37
|
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
38
38
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.add_dependency(%q<monetize>.freeze, [">= 0"])
|
42
42
|
s.add_dependency(%q<json>.freeze, [">= 0"])
|
43
43
|
s.add_dependency(%q<tins>.freeze, [">= 0"])
|
44
|
-
s.add_dependency(%q<mize>.freeze, ["
|
44
|
+
s.add_dependency(%q<mize>.freeze, ["~> 0.3", ">= 0.3.4"])
|
45
45
|
end
|
46
46
|
else
|
47
47
|
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
@@ -51,6 +51,6 @@ Gem::Specification.new do |s|
|
|
51
51
|
s.add_dependency(%q<monetize>.freeze, [">= 0"])
|
52
52
|
s.add_dependency(%q<json>.freeze, [">= 0"])
|
53
53
|
s.add_dependency(%q<tins>.freeze, [">= 0"])
|
54
|
-
s.add_dependency(%q<mize>.freeze, ["
|
54
|
+
s.add_dependency(%q<mize>.freeze, ["~> 0.3", ">= 0.3.4"])
|
55
55
|
end
|
56
56
|
end
|
@@ -30,7 +30,7 @@ class ComplexConfig::Encryption
|
|
30
30
|
encrypted, iv, auth_tag = text.split('--').map { |v| base64_decode(v) }
|
31
31
|
|
32
32
|
auth_tag.nil? || auth_tag.bytes.length != 16 and
|
33
|
-
raise ComplexConfig::DecryptionFailed, "auth_tag
|
33
|
+
raise ComplexConfig::DecryptionFailed, "auth_tag was invalid"
|
34
34
|
|
35
35
|
@cipher.decrypt
|
36
36
|
@cipher.key = @secret
|
@@ -42,6 +42,8 @@ class ComplexConfig::Encryption
|
|
42
42
|
decrypted_data << @cipher.final
|
43
43
|
|
44
44
|
Marshal.load(decrypted_data)
|
45
|
+
rescue OpenSSL::Cipher::CipherError
|
46
|
+
raise ComplexConfig::DecryptionFailed, "decryption failed with this key"
|
45
47
|
end
|
46
48
|
|
47
49
|
private
|
@@ -113,7 +113,12 @@ class ComplexConfig::Settings < BasicObject
|
|
113
113
|
each.count
|
114
114
|
end
|
115
115
|
|
116
|
+
def empty?
|
117
|
+
size == 0
|
118
|
+
end
|
119
|
+
|
116
120
|
def to_s(pair_sep: ' = ', path_sep: ?.)
|
121
|
+
empty? and return self.class.name
|
117
122
|
pathes(path_sep: path_sep).inject('') do |result, (path, value)|
|
118
123
|
result << "#{path}#{pair_sep}#{value.inspect}\n"
|
119
124
|
end
|
@@ -24,4 +24,12 @@ RSpec.describe ComplexConfig::Encryption do
|
|
24
24
|
it 'can decrypt' do
|
25
25
|
expect(enc.decrypt(encrypted)).to eq value
|
26
26
|
end
|
27
|
+
|
28
|
+
it 'raises exception if key is invalid' do
|
29
|
+
enc = described_class.new Tins::Token.new(
|
30
|
+
alphabet: (0..255).map(&:chr).join, bits: secret.size * 8
|
31
|
+
)
|
32
|
+
expect { enc.decrypt(encrypted) }.to\
|
33
|
+
raise_error ComplexConfig::DecryptionFailed
|
34
|
+
end
|
27
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'complex_config/plugins/enable'
|
3
3
|
|
4
|
-
RSpec.describe ComplexConfig::
|
4
|
+
RSpec.describe ComplexConfig::Plugins do
|
5
5
|
let :provider do
|
6
6
|
ComplexConfig::Provider
|
7
7
|
end
|
@@ -15,7 +15,7 @@ RSpec.describe ComplexConfig::Settings do
|
|
15
15
|
]
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
18
|
+
context described_class::URI do
|
19
19
|
it 'can return an URL string' do
|
20
20
|
expect(settings.foo.test_url).to eq 'http://www.ping.de'
|
21
21
|
end
|
@@ -33,7 +33,7 @@ RSpec.describe ComplexConfig::Settings do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context
|
36
|
+
context described_class::MONEY do
|
37
37
|
it 'can return a Fixnum' do
|
38
38
|
expect(settings.foo.cash_in_cents).to eq 100_00
|
39
39
|
end
|
@@ -2,23 +2,19 @@ require 'spec_helper'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
RSpec.describe ComplexConfig::Provider do
|
5
|
-
let :provider do
|
6
|
-
ComplexConfig::Provider
|
7
|
-
end
|
8
|
-
|
9
5
|
reset_new_config = -> * {
|
10
|
-
|
11
|
-
|
6
|
+
described_class.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
7
|
+
described_class.key = nil
|
12
8
|
ENV['COMPLEX_CONFIG_KEY'] = nil
|
13
9
|
ENV['RAILS_MASTER_KEY'] = nil
|
14
|
-
FileUtils.rm_f(
|
15
|
-
FileUtils.rm_f(
|
16
|
-
FileUtils.rm_f(
|
10
|
+
FileUtils.rm_f(described_class.config_dir + 'new_config.yml')
|
11
|
+
FileUtils.rm_f(described_class.config_dir + 'new_config.yml.enc')
|
12
|
+
FileUtils.rm_f(described_class.config_dir + 'new_config.yml.key')
|
17
13
|
}
|
18
14
|
|
19
15
|
after do
|
20
16
|
instance_eval(&reset_new_config)
|
21
|
-
|
17
|
+
described_class.flush_cache
|
22
18
|
end
|
23
19
|
|
24
20
|
context 'plugin' do
|
@@ -37,17 +33,17 @@ RSpec.describe ComplexConfig::Provider do
|
|
37
33
|
end
|
38
34
|
|
39
35
|
before do
|
40
|
-
|
36
|
+
described_class.plugins.clear
|
41
37
|
end
|
42
38
|
|
43
39
|
it 'can add one' do
|
44
|
-
expect {
|
40
|
+
expect { described_class.add_plugin plugin }.to change { described_class.plugins.size }.by(1)
|
45
41
|
end
|
46
42
|
|
47
43
|
it 'can apply plugins' do
|
48
|
-
|
44
|
+
described_class.add_plugin plugin
|
49
45
|
allow(setting).to receive(:skip).and_throw :skip
|
50
|
-
expect(
|
46
|
+
expect(described_class.apply_plugins(setting, :evaluate_plugin)).to eq :evaluated
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
@@ -57,161 +53,161 @@ RSpec.describe ComplexConfig::Provider do
|
|
57
53
|
def self.root
|
58
54
|
end
|
59
55
|
end
|
60
|
-
|
56
|
+
described_class.config_dir = nil
|
61
57
|
end
|
62
58
|
|
63
59
|
it 'can derive rails root from Rails.root if present' do
|
64
60
|
allow(::Rails).to receive(:root).and_return Pathname.new('bar')
|
65
61
|
dir = Pathname.new('bar/config')
|
66
|
-
expect(
|
62
|
+
expect(described_class.config_dir).to eq dir
|
67
63
|
end
|
68
64
|
|
69
65
|
it 'falls back to current working directory by default' do
|
70
|
-
expect(
|
66
|
+
expect(described_class.config_dir).to eq Pathname.pwd + 'config'
|
71
67
|
end
|
72
68
|
|
73
69
|
it 'can derive master_key_pathname' do
|
74
|
-
expect(
|
70
|
+
expect(described_class.master_key_pathname).to eq\
|
75
71
|
Pathname.pwd.join('config/master.key')
|
76
72
|
end
|
77
73
|
|
78
74
|
it 'can set master_key_pathname' do
|
79
|
-
|
80
|
-
expect(
|
75
|
+
described_class.master_key_pathname = 'foo'
|
76
|
+
expect(described_class.master_key_pathname).to eq 'foo'
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
84
80
|
context 'reading configurations' do
|
85
81
|
it 'can read a configuration file' do
|
86
82
|
expect(
|
87
|
-
|
83
|
+
described_class.config(asset('config.yml'))
|
88
84
|
).to be_a ComplexConfig::Settings
|
89
85
|
end
|
90
86
|
|
91
87
|
it 'has deep frozen settings' do
|
92
|
-
settings =
|
88
|
+
settings = described_class.config(asset('config.yml'))
|
93
89
|
expect(settings).to be_frozen
|
94
90
|
end
|
95
91
|
|
96
92
|
it 'deep freezing can be disabled' do
|
97
93
|
begin
|
98
|
-
|
99
|
-
settings =
|
94
|
+
described_class.deep_freeze = false
|
95
|
+
settings = described_class.config(asset('config.yml'))
|
100
96
|
expect(settings).not_to be_frozen
|
101
97
|
ensure
|
102
|
-
|
98
|
+
described_class.deep_freeze = true
|
103
99
|
end
|
104
100
|
end
|
105
101
|
|
106
102
|
it 'handles missing configuration files' do
|
107
|
-
expect {
|
103
|
+
expect { described_class.config(asset('nix_config.yml')) }.to\
|
108
104
|
raise_error(ComplexConfig::ConfigurationFileMissing)
|
109
105
|
end
|
110
106
|
|
111
107
|
it 'handles syntax errors in configuration files' do
|
112
|
-
expect {
|
108
|
+
expect { described_class.config(asset('broken_config.yml')) }.to\
|
113
109
|
raise_error(ComplexConfig::ConfigurationSyntaxError)
|
114
110
|
end
|
115
111
|
end
|
116
112
|
|
117
113
|
context 'writing configurations' do
|
118
114
|
before do
|
119
|
-
|
115
|
+
described_class.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
120
116
|
end
|
121
117
|
|
122
118
|
let :config do
|
123
|
-
|
119
|
+
described_class.config(asset('config.yml'))
|
124
120
|
end
|
125
121
|
|
126
122
|
it 'can be written' do
|
127
|
-
|
128
|
-
expect(
|
123
|
+
described_class.write_config('new_config', value: config)
|
124
|
+
expect(described_class.config(asset('new_config.yml'))).to eq config
|
129
125
|
end
|
130
126
|
|
131
127
|
it 'can be changed and written' do
|
132
|
-
|
128
|
+
described_class.deep_freeze = false
|
133
129
|
config.development.config.baz = 'something else'
|
134
|
-
|
135
|
-
expect(
|
130
|
+
described_class.write_config('new_config', value: config)
|
131
|
+
expect(described_class.config(asset('new_config.yml')).development.config.baz).to eq 'something else'
|
136
132
|
end
|
137
133
|
end
|
138
134
|
|
139
135
|
context 'reading encrypted configurations' do
|
140
136
|
before do
|
141
|
-
|
137
|
+
described_class.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
142
138
|
end
|
143
139
|
|
144
140
|
let :key do
|
145
|
-
IO.binread(
|
141
|
+
IO.binread(described_class.config_dir + 'with-key-file.yml.key')
|
146
142
|
end
|
147
143
|
|
148
144
|
it 'can read when key is set by accessor' do
|
149
|
-
|
150
|
-
expect(
|
151
|
-
expect(
|
145
|
+
described_class.key = key
|
146
|
+
expect(described_class.key).to eq key.chomp
|
147
|
+
expect(described_class['without-key-file'].development.foo.bar).to eq 'baz'
|
152
148
|
end
|
153
149
|
|
154
150
|
it 'can read when key is in ENV var' do
|
155
151
|
ENV['RAILS_MASTER_KEY'] = key
|
156
|
-
expect(
|
152
|
+
expect(described_class['without-key-file'].development.foo.bar).to eq 'baz'
|
157
153
|
ENV['RAILS_MASTER_KEY'] = nil
|
158
154
|
end
|
159
155
|
|
160
156
|
it 'can read when key is stored in file' do
|
161
|
-
expect(
|
157
|
+
expect(described_class['with-key-file'].development.foo.bar).to eq 'baz'
|
162
158
|
end
|
163
159
|
end
|
164
160
|
|
165
161
|
context 'writing encrypted configurations' do
|
166
162
|
before do
|
167
|
-
|
163
|
+
described_class.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
168
164
|
instance_eval(&reset_new_config)
|
169
165
|
end
|
170
166
|
|
171
167
|
let :config do
|
172
|
-
|
168
|
+
described_class.config(asset('config.yml'))
|
173
169
|
end
|
174
170
|
|
175
171
|
it 'can be written with random key' do
|
176
|
-
key =
|
177
|
-
|
178
|
-
expect(
|
172
|
+
key = described_class.write_config('new_config', value: config, encrypt: :random, store_key: false)
|
173
|
+
described_class.key = key
|
174
|
+
expect(described_class.config(asset('new_config.yml'))).to eq config
|
179
175
|
end
|
180
176
|
|
181
177
|
it 'can be written with random key and store key' do
|
182
|
-
|
183
|
-
expect(
|
178
|
+
described_class.write_config('new_config', value: config, encrypt: :random, store_key: true)
|
179
|
+
expect(described_class.config(asset('new_config.yml'))).to eq config
|
184
180
|
end
|
185
181
|
|
186
182
|
it 'can be written with passed key' do
|
187
183
|
key = SecureRandom.hex(16)
|
188
|
-
|
189
|
-
|
190
|
-
expect(
|
184
|
+
described_class.write_config('new_config', value: config, encrypt: key)
|
185
|
+
described_class.key = key
|
186
|
+
expect(described_class.config(asset('new_config.yml'))).to eq config
|
191
187
|
end
|
192
188
|
|
193
189
|
it 'can be written with configured key' do
|
194
|
-
|
195
|
-
expect(
|
190
|
+
described_class.write_config('new_config', value: config)
|
191
|
+
expect(described_class.config(asset('new_config.yml'))).to eq config
|
196
192
|
end
|
197
193
|
|
198
194
|
it 'can be written with COMPLEX_CONFIG_KEY key' do
|
199
195
|
ENV['COMPLEX_CONFIG_KEY'] = SecureRandom.hex(16)
|
200
|
-
k =
|
196
|
+
k = described_class.write_config('new_config', value: config, encrypt: true)
|
201
197
|
expect(k).to eq ENV['COMPLEX_CONFIG_KEY']
|
202
|
-
expect(
|
198
|
+
expect(described_class.config(asset('new_config.yml'))).to eq config
|
203
199
|
end
|
204
200
|
|
205
201
|
it 'can be written with RAILS_MASTER_KEY key' do
|
206
202
|
ENV['RAILS_MASTER_KEY'] = SecureRandom.hex(16)
|
207
|
-
k =
|
203
|
+
k = described_class.write_config('new_config', value: config, encrypt: true)
|
208
204
|
expect(k).to eq ENV['RAILS_MASTER_KEY']
|
209
|
-
expect(
|
205
|
+
expect(described_class.config(asset('new_config.yml'))).to eq config
|
210
206
|
end
|
211
207
|
|
212
208
|
it 'can encrypt file content with RAILS_MASTER_KEY key' do
|
213
209
|
ENV['RAILS_MASTER_KEY'] = SecureRandom.hex(16)
|
214
|
-
encrypted =
|
210
|
+
encrypted = described_class.encrypt_config(asset('new_config.yml'), 'test')
|
215
211
|
expect(encrypted).not_to be_empty
|
216
212
|
ks = ComplexConfig::KeySource.new(env_var: 'RAILS_MASTER_KEY')
|
217
213
|
expect(
|
@@ -220,58 +216,58 @@ RSpec.describe ComplexConfig::Provider do
|
|
220
216
|
end
|
221
217
|
|
222
218
|
it 'can be changed and written' do
|
223
|
-
|
224
|
-
expect(
|
219
|
+
described_class.deep_freeze = false
|
220
|
+
expect(described_class.config(asset('config.yml')).development.config.baz).to eq 'something'
|
225
221
|
config.development.config.baz = 'something else'
|
226
|
-
|
227
|
-
expect(
|
222
|
+
described_class.write_config('new_config', value: config)
|
223
|
+
expect(described_class.config(asset('new_config.yml')).development.config.baz).to eq 'something else'
|
228
224
|
#
|
229
|
-
new_config =
|
225
|
+
new_config = described_class.config(asset('new_config.yml'), :new_config)
|
230
226
|
new_config.development.config.baz = 'something else else'
|
231
|
-
|
232
|
-
expect(
|
227
|
+
described_class.write_config new_config
|
228
|
+
expect(described_class.config(asset('new_config.yml')).development.config.baz).to eq 'something else else'
|
233
229
|
#
|
234
|
-
new_config =
|
235
|
-
|
236
|
-
#expect(
|
230
|
+
new_config = described_class.config(asset('new_config.yml'), :new_config)
|
231
|
+
described_class.write_config(new_config, value: { development: { config: { baz: 'even more else' } } })
|
232
|
+
#expect(described_class.config(asset('new_config.yml')).development.config.baz).to eq 'something else else'
|
237
233
|
end
|
238
234
|
end
|
239
235
|
|
240
236
|
context 'handling configuration files with []' do
|
241
237
|
before do
|
242
|
-
|
238
|
+
described_class.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
243
239
|
end
|
244
240
|
|
245
241
|
it 'returns the correct configuration' do
|
246
|
-
expect(
|
242
|
+
expect(described_class['config']).to be_a ComplexConfig::Settings
|
247
243
|
end
|
248
244
|
|
249
245
|
it 'caches the configuration after first use' do
|
250
246
|
expect {
|
251
|
-
expect(
|
247
|
+
expect(described_class['config']).to be_a ComplexConfig::Settings
|
252
248
|
}.to change {
|
253
|
-
|
249
|
+
described_class.instance.__send__(:__mize_cache__).instance_variable_get(:@data).size
|
254
250
|
}.by(1)
|
255
|
-
expect(
|
256
|
-
expect(
|
251
|
+
expect(described_class).not_to receive(:config)
|
252
|
+
expect(described_class['config']).to be_a ComplexConfig::Settings
|
257
253
|
end
|
258
254
|
|
259
255
|
it 'can flush loaded configurations' do
|
260
|
-
expect(
|
256
|
+
expect(described_class['config']).to be_a ComplexConfig::Settings
|
261
257
|
result = nil
|
262
258
|
expect {
|
263
|
-
result =
|
259
|
+
result = described_class.flush_cache
|
264
260
|
}.to change {
|
265
|
-
|
261
|
+
described_class.instance.__send__(:__mize_cache__).instance_variable_get(:@data).size
|
266
262
|
}.by(-1)
|
267
|
-
expect(result).to be_a
|
263
|
+
expect(result).to be_a described_class
|
268
264
|
end
|
269
265
|
end
|
270
266
|
|
271
267
|
context 'evaluating configuration files with ERB' do
|
272
268
|
it 'evaluates a config file correctly' do
|
273
269
|
expect(
|
274
|
-
|
270
|
+
described_class.config(asset('config.yml')).development.config.pi
|
275
271
|
).to be_within(1e-6).of Math::PI
|
276
272
|
end
|
277
273
|
end
|
@@ -287,33 +283,33 @@ RSpec.describe ComplexConfig::Provider do
|
|
287
283
|
end
|
288
284
|
|
289
285
|
after do
|
290
|
-
|
286
|
+
described_class.env = nil
|
291
287
|
end
|
292
288
|
|
293
289
|
it 'can be set manually' do
|
294
|
-
|
295
|
-
expect(
|
290
|
+
described_class.env = 'foobar'
|
291
|
+
expect(described_class.env).to eq 'foobar'
|
296
292
|
end
|
297
293
|
|
298
294
|
it 'can derive environments from Rails.env if present' do
|
299
295
|
expect(Rails).to receive(:env).and_return('foobar')
|
300
|
-
expect(
|
296
|
+
expect(described_class.env).to eq 'foobar'
|
301
297
|
end
|
302
298
|
|
303
299
|
it 'falls back to "development" as a default' do
|
304
|
-
expect(
|
300
|
+
expect(described_class.env).to eq 'development'
|
305
301
|
end
|
306
302
|
|
307
303
|
end
|
308
304
|
|
309
305
|
context 'shared' do
|
310
306
|
before do
|
311
|
-
|
307
|
+
described_class.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
312
308
|
end
|
313
309
|
|
314
310
|
it 'can share values' do
|
315
|
-
expect(
|
316
|
-
expect(
|
311
|
+
expect(described_class['config'].development.shared).to eq true
|
312
|
+
expect(described_class['config'].test.shared).to eq true
|
317
313
|
end
|
318
314
|
end
|
319
315
|
end
|
@@ -7,7 +7,7 @@ RSpec.describe ComplexConfig::Settings do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
let :settings do
|
10
|
-
|
10
|
+
described_class[
|
11
11
|
foo: {
|
12
12
|
bar: {
|
13
13
|
baz: true
|
@@ -18,12 +18,12 @@ RSpec.describe ComplexConfig::Settings do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'can be initialized with a hash' do
|
21
|
-
s =
|
21
|
+
s = described_class.new(foo: 'bar')
|
22
22
|
expect(s.foo).to eq 'bar'
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'can be duped and changed' do
|
26
|
-
s =
|
26
|
+
s = described_class.new(foo: 'bar')
|
27
27
|
t = s.dup
|
28
28
|
expect(s.foo).to eq 'bar'
|
29
29
|
t.foo = 'baz'
|
@@ -43,6 +43,10 @@ RSpec.describe ComplexConfig::Settings do
|
|
43
43
|
expect(settings.size).to eq 1
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'can be empty' do
|
47
|
+
expect(described_class.new).to be_empty
|
48
|
+
end
|
49
|
+
|
46
50
|
it 'can set its attributes via index method' do
|
47
51
|
expect {
|
48
52
|
settings['blub'] = 'blub'
|
@@ -87,8 +91,12 @@ foo/qux → "quux"
|
|
87
91
|
EOT
|
88
92
|
end
|
89
93
|
|
94
|
+
it 'responds with class name if #to_s is called on empty settigs' do
|
95
|
+
expect(described_class.new.to_s).to eq described_class.name
|
96
|
+
end
|
97
|
+
|
90
98
|
it 'can be represented as a string if it has arrays' do
|
91
|
-
settings[:ary] =
|
99
|
+
settings[:ary] = described_class[ [ 1, { nested: 2 }, 3 ] ]
|
92
100
|
expect(settings.to_s).to eq <<EOT
|
93
101
|
foo.bar.baz = true
|
94
102
|
foo.qux = "quux"
|
@@ -126,12 +134,12 @@ EOT
|
|
126
134
|
end
|
127
135
|
|
128
136
|
it 'handles arrays correctly' do
|
129
|
-
settings =
|
137
|
+
settings = described_class[ary: [ 1, { hsh: 2 }, 3 ]]
|
130
138
|
expect(settings.to_h).to eq(ary: [ 1, { hsh: 2 }, 3 ])
|
131
139
|
end
|
132
140
|
|
133
141
|
it 'returns zip if it was set' do
|
134
|
-
settings =
|
142
|
+
settings = described_class[zip: 'a string']
|
135
143
|
expect(settings.zip).to eq 'a string'
|
136
144
|
end
|
137
145
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: complex_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -161,7 +161,6 @@ files:
|
|
161
161
|
- Gemfile
|
162
162
|
- README.md
|
163
163
|
- Rakefile
|
164
|
-
- TODO.md
|
165
164
|
- VERSION
|
166
165
|
- bin/complex_config
|
167
166
|
- complex_config.gemspec
|
@@ -221,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
220
|
version: '0'
|
222
221
|
requirements: []
|
223
222
|
rubyforge_project:
|
224
|
-
rubygems_version: 2.7.
|
223
|
+
rubygems_version: 2.7.8
|
225
224
|
signing_key:
|
226
225
|
specification_version: 4
|
227
226
|
summary: configuration library
|
data/TODO.md
DELETED