config_reader 3.0.0 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/config_reader/config_hash.rb +1 -3
- data/lib/config_reader/version.rb +1 -1
- data/lib/config_reader.rb +48 -40
- data/spec/config_reader_spec.rb +1 -1
- data/spec/sekrets_config.yml.enc +2 -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: ff6af0d4ec72275cf3d8186e9f889a8a0dee9c94e9ca16552d8a7da3e4f057a0
|
4
|
+
data.tar.gz: 6be5d22c4fb82c0fb60927a6f63d5abe287f2dbc7bedb87e67fb0bfa39dd7bb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 600ea0a78d494acecc50f787fa8ab4d8594592f5ccd70dfbc892b3e4068f31c12dc79c56d7c4801089dc47834af26da65bfbacceef09e8d3ee3962b352720ff6
|
7
|
+
data.tar.gz: 2d39e35dbcd26edd3b9a50e364b0d4ec1dd091691ba43989baaf386d28212c04250fdc04946f636b728fb3754546d65c3ac74be2ff74e5d5ea52c24a0867c570
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 3.0.
|
3
|
+
## 3.0.2 2024-12-13
|
4
|
+
|
5
|
+
Fix an issue when merging multiple envs.
|
6
|
+
|
7
|
+
## 3.0.1 2024-12-13 (yanked)
|
8
|
+
|
9
|
+
Don't merge! in deep_merge
|
10
|
+
|
11
|
+
## 3.0.0 2024-12-12 (yanked)
|
4
12
|
|
5
13
|
Update to latest Sekrets (1.14.0)
|
6
14
|
Explicitly require abbrev gem
|
@@ -24,9 +24,7 @@ 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, *)
|
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,11 +36,11 @@ class ConfigReader
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def deep_merge(hash, other_hash)
|
34
|
-
hash.merge
|
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
|
38
|
-
other_val
|
43
|
+
hash[key] = other_val
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
@@ -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
|
99
|
-
|
100
|
-
sekrets
|
101
89
|
end
|
102
90
|
|
103
|
-
def
|
104
|
-
|
105
|
-
env_keys = conf.keys - ["defaults"]
|
106
|
-
env = configuration.environment
|
91
|
+
def load_yaml
|
92
|
+
permitted_classes = configuration.permitted_classes.to_a + [Symbol]
|
107
93
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
+
)
|
112
106
|
end
|
107
|
+
end
|
113
108
|
|
114
|
-
|
115
|
-
|
116
|
-
key_hash = deep_merge(defaults, sekrets[key]) if sekrets && sekrets[key]
|
109
|
+
def merge_all_configs(conf, defaults, sekrets)
|
110
|
+
@envs = {}
|
117
111
|
|
118
|
-
|
112
|
+
(conf.keys - ["defaults"]).each do |env|
|
113
|
+
key_hash = deep_merge(defaults.dup, conf[env]) if conf[env]
|
114
|
+
key_hash = deep_merge(key_hash, sekrets[env]) if sekrets&.[](env)
|
115
|
+
|
116
|
+
@envs[env] = ConfigHash.convert_hash(
|
119
117
|
key_hash,
|
120
118
|
configuration.ignore_missing_keys
|
121
119
|
)
|
122
120
|
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def merge_configs(conf, sekrets)
|
124
|
+
defaults = conf["defaults"]
|
125
|
+
|
126
|
+
if sekrets&.[]("defaults")
|
127
|
+
defaults = deep_merge(defaults, sekrets["defaults"])
|
128
|
+
end
|
129
|
+
|
130
|
+
merge_all_configs(conf, defaults, sekrets)
|
123
131
|
|
124
|
-
@envs[
|
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,7 +27,7 @@ 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
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Moen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abbrev
|