config_reader 3.0.1 → 3.0.3
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/CHANGELOG.md +10 -2
- data/lib/config_reader/config_hash.rb +2 -4
- data/lib/config_reader/version.rb +1 -1
- data/lib/config_reader.rb +47 -39
- data/spec/config_reader_spec.rb +3 -2
- data/spec/multi_envs/merge_config.rb +6 -0
- data/spec/multi_envs/merge_config.yml +15 -0
- data/spec/multi_envs/merge_spec.rb +18 -0
- data/spec/sekrets_config.yml.enc +2 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f34ccb03e315e9301ebedd211dca7e5fde4842e14e15a4f809ee6c0e5f16cd
|
4
|
+
data.tar.gz: 45f064ce87458166d7ccec76e18d8f3ceeaee36ac91665d6c0db6037f8e84d9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 297c24bc4211132943f69e3a5b85f7d2686389f481c4b3b51fc10d530abebd638bb2705b274ac4546be65f9738331f573b39f10ea5b8d2d088270653c41058d5
|
7
|
+
data.tar.gz: 171d64da65475f7188967b1152715ec63730a4322b814372b66c4f5da1f8601b9619ff82c437907efc3acaf3e9ecff06bbcb7cd068584a0adb44e613cfb5c024
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 3.0.
|
3
|
+
## 3.0.3 2025-01-06
|
4
|
+
|
5
|
+
Fix a bug in deep merge where values weren't getting set properly.
|
6
|
+
|
7
|
+
## 3.0.2 2024-12-13
|
8
|
+
|
9
|
+
Fix an issue when merging multiple envs.
|
10
|
+
|
11
|
+
## 3.0.1 2024-12-13 (yanked)
|
4
12
|
|
5
13
|
Don't merge! in deep_merge
|
6
14
|
|
7
|
-
## 3.0.0 2024-12-12
|
15
|
+
## 3.0.0 2024-12-12 (yanked)
|
8
16
|
|
9
17
|
Update to latest Sekrets (1.14.0)
|
10
18
|
Explicitly require abbrev gem
|
@@ -24,13 +24,11 @@ class ConfigReader
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def method_missing(key, *args, &block)
|
27
|
-
|
28
|
-
rescue KeyError, NoMethodError => e # skipcq: RB-P1001
|
29
|
-
raise e unless ignore_missing_keys
|
27
|
+
ignore_missing_keys ? self[key] : fetch(key)
|
30
28
|
end
|
31
29
|
|
32
30
|
def respond_to_missing?(m, *)
|
33
|
-
|
31
|
+
key?(m)
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
data/lib/config_reader.rb
CHANGED
@@ -2,6 +2,11 @@ require "config_reader/version"
|
|
2
2
|
require "config_reader/config_hash"
|
3
3
|
require "psych"
|
4
4
|
|
5
|
+
begin
|
6
|
+
require "sekrets"
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
5
10
|
begin
|
6
11
|
require "erb"
|
7
12
|
rescue LoadError
|
@@ -31,7 +36,7 @@ class ConfigReader
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def deep_merge(hash, other_hash)
|
34
|
-
hash.merge(other_hash) do |
|
39
|
+
hash.merge(other_hash) do |key, this_val, other_val|
|
35
40
|
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
36
41
|
deep_merge(this_val, other_val)
|
37
42
|
else
|
@@ -58,26 +63,13 @@ class ConfigReader
|
|
58
63
|
end
|
59
64
|
|
60
65
|
def inspect
|
61
|
-
|
66
|
+
config.inspect
|
62
67
|
end
|
63
68
|
|
64
69
|
def load_config
|
65
70
|
raise "No config file set" unless find_config
|
66
71
|
|
67
|
-
conf =
|
68
|
-
if defined?(ERB)
|
69
|
-
Psych.safe_load(
|
70
|
-
ERB.new(File.read(find_config)).result,
|
71
|
-
aliases: true,
|
72
|
-
permitted_classes: configuration.permitted_classes.to_a + [Symbol]
|
73
|
-
)
|
74
|
-
else
|
75
|
-
Psych.safe_load_file(
|
76
|
-
File.read(find_config),
|
77
|
-
aliases: true,
|
78
|
-
permitted_classes: configuration.permitted_classes.to_a + [Symbol]
|
79
|
-
)
|
80
|
-
end
|
72
|
+
conf = load_yaml
|
81
73
|
|
82
74
|
raise "No config found" unless conf
|
83
75
|
|
@@ -85,43 +77,59 @@ class ConfigReader
|
|
85
77
|
end
|
86
78
|
|
87
79
|
def load_sekrets
|
88
|
-
sekrets = {}
|
89
|
-
|
90
80
|
if configuration.sekrets_file
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
81
|
+
if !defined?(::Sekrets)
|
82
|
+
raise ArgumentError,
|
83
|
+
"You specified a sekrets_file, but the sekrets gem isn't available."
|
84
|
+
else
|
85
|
+
::Sekrets.settings_for(configuration.sekrets_file) ||
|
86
|
+
raise("No sekrets found")
|
97
87
|
end
|
98
88
|
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def load_yaml
|
92
|
+
permitted_classes = configuration.permitted_classes.to_a + [Symbol]
|
99
93
|
|
100
|
-
|
94
|
+
if defined?(ERB)
|
95
|
+
Psych.safe_load(
|
96
|
+
ERB.new(File.read(find_config)).result,
|
97
|
+
aliases: true,
|
98
|
+
permitted_classes: permitted_classes
|
99
|
+
)
|
100
|
+
else
|
101
|
+
Psych.safe_load_file(
|
102
|
+
File.read(find_config),
|
103
|
+
aliases: true,
|
104
|
+
permitted_classes: permitted_classes
|
105
|
+
)
|
106
|
+
end
|
101
107
|
end
|
102
108
|
|
103
|
-
def
|
109
|
+
def merge_all_configs(conf, defaults, sekrets)
|
104
110
|
@envs = {}
|
105
|
-
env_keys = conf.keys - ["defaults"]
|
106
|
-
env = configuration.environment
|
107
111
|
|
108
|
-
|
112
|
+
conf.keys.each do |env|
|
113
|
+
env_hash = deep_merge(defaults, conf[env] || {})
|
114
|
+
env_hash = deep_merge(env_hash, sekrets[env] || {}) if sekrets
|
109
115
|
|
110
|
-
|
111
|
-
|
116
|
+
@envs[env] = ConfigHash.convert_hash(
|
117
|
+
env_hash,
|
118
|
+
configuration.ignore_missing_keys
|
119
|
+
)
|
112
120
|
end
|
121
|
+
end
|
113
122
|
|
114
|
-
|
115
|
-
|
116
|
-
key_hash = deep_merge(defaults, sekrets[key]) if sekrets && sekrets[key]
|
123
|
+
def merge_configs(conf, sekrets)
|
124
|
+
defaults = conf["defaults"]
|
117
125
|
|
118
|
-
|
119
|
-
|
120
|
-
configuration.ignore_missing_keys
|
121
|
-
)
|
126
|
+
if sekrets&.[]("defaults")
|
127
|
+
defaults = deep_merge(defaults, sekrets["defaults"])
|
122
128
|
end
|
123
129
|
|
124
|
-
|
130
|
+
merge_all_configs(conf, defaults, sekrets)
|
131
|
+
|
132
|
+
@envs[configuration.environment]
|
125
133
|
end
|
126
134
|
|
127
135
|
def method_missing(key, *_args, &_block)
|
data/spec/config_reader_spec.rb
CHANGED
@@ -27,13 +27,14 @@ describe "ConfigReader" do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should raise on missing nested key with #key accessor" do
|
30
|
-
expect { TestConfig.nested_key.missing }.to raise_error(
|
30
|
+
expect { TestConfig.nested_key.missing }.to raise_error(KeyError)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "all envs available" do
|
35
35
|
it "should have all envs available" do
|
36
|
-
|
36
|
+
TestConfig.reload
|
37
|
+
expect(TestConfig.envs.keys).to eq(%w[defaults test not_test])
|
37
38
|
end
|
38
39
|
|
39
40
|
it "should have ConfigHash for all envs" do
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "multi_envs/merge_config"
|
3
|
+
|
4
|
+
describe "ConfigReader" do
|
5
|
+
before(:all) { MergeConfig.reload }
|
6
|
+
|
7
|
+
describe "all envs available" do
|
8
|
+
it "should have all envs available" do
|
9
|
+
expect(MergeConfig.envs.keys).to eq(%w[defaults test not_test merge])
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have ConfigHash for all envs" do
|
13
|
+
expect(MergeConfig.envs["test"].app_name).to eq("test_app")
|
14
|
+
expect(MergeConfig.envs["not_test"].app_name).to eq("not_test_app")
|
15
|
+
expect(MergeConfig.envs["merge"]).to eq(MergeConfig.envs["defaults"])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/sekrets_config.yml.enc
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Moen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abbrev
|
@@ -113,6 +113,9 @@ files:
|
|
113
113
|
- lib/config_reader/config_hash.rb
|
114
114
|
- lib/config_reader/version.rb
|
115
115
|
- spec/config_reader_spec.rb
|
116
|
+
- spec/multi_envs/merge_config.rb
|
117
|
+
- spec/multi_envs/merge_config.yml
|
118
|
+
- spec/multi_envs/merge_spec.rb
|
116
119
|
- spec/no_key_no_error_config.rb
|
117
120
|
- spec/sekrets_config.rb
|
118
121
|
- spec/sekrets_config.yml.enc
|