runger_config 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/generators/runger/app_config/app_config_generator.rb +6 -10
- data/lib/generators/runger/config/config_generator.rb +44 -41
- data/lib/generators/runger/install/install_generator.rb +35 -37
- data/lib/runger/auto_cast.rb +3 -3
- data/lib/runger/config.rb +114 -94
- data/lib/runger/dynamic_config.rb +21 -23
- data/lib/runger/ejson_parser.rb +24 -24
- data/lib/runger/env.rb +50 -52
- data/lib/runger/ext/deep_dup.rb +33 -36
- data/lib/runger/ext/deep_freeze.rb +28 -32
- data/lib/runger/ext/flatten_names.rb +23 -27
- data/lib/runger/ext/hash.rb +26 -29
- data/lib/runger/ext/string_constantize.rb +12 -15
- data/lib/runger/loaders/base.rb +11 -15
- data/lib/runger/loaders/doppler.rb +38 -42
- data/lib/runger/loaders/ejson.rb +65 -63
- data/lib/runger/loaders/env.rb +6 -10
- data/lib/runger/loaders/yaml.rb +69 -66
- data/lib/runger/loaders.rb +69 -71
- data/lib/runger/option_parser_builder.rb +16 -18
- data/lib/runger/optparse_config.rb +11 -10
- data/lib/runger/rails/autoload.rb +24 -26
- data/lib/runger/rails/config.rb +13 -17
- data/lib/runger/rails/loaders/credentials.rb +53 -57
- data/lib/runger/rails/loaders/secrets.rb +21 -25
- data/lib/runger/rails/loaders/yaml.rb +1 -6
- data/lib/runger/rails/loaders.rb +3 -3
- data/lib/runger/rails/settings.rb +49 -49
- data/lib/runger/rails.rb +9 -11
- data/lib/runger/railtie.rb +3 -2
- data/lib/runger/rbs.rb +29 -29
- data/lib/runger/settings.rb +82 -84
- data/lib/runger/testing/helpers.rb +26 -28
- data/lib/runger/testing.rb +2 -2
- data/lib/runger/tracing.rb +143 -136
- data/lib/runger/type_casting.rb +16 -11
- data/lib/runger/utils/which.rb +10 -12
- data/lib/runger/version.rb +1 -1
- data/lib/runger.rb +1 -1
- data/lib/runger_config.rb +34 -27
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81aff8e187347108683968d2aa3a9fecae6a7195d6261b0809658031204bef71
|
4
|
+
data.tar.gz: 740300783062b617a412f05c9b1f65757a81bef733a77e0e86361ce41a4a00b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42f3055ac5a872743e63b982a74afc7a26852681432f091e520cf690df78eef5787f84390f620fd7210edf67cada60c5aa08c127eb97ef1ef478e0603ff16020
|
7
|
+
data.tar.gz: 0cf7835d45cc7bbbcfc6247d58890beaef9e8cfd8784534bc97281857a5ebfec4d75e763a86bf195b96759c2be740d0b78247aa4aef30c79c6994203a8a0bb2f
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'generators/runger/config/config_generator'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
class AppConfigGenerator < ConfigGenerator
|
8
|
-
source_root ConfigGenerator.source_root
|
5
|
+
class Runger::Generators::AppConfigGenerator < Runger::Generators::ConfigGenerator
|
6
|
+
source_root ::Runger::Generators::ConfigGenerator.source_root
|
9
7
|
|
10
|
-
|
8
|
+
private
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
10
|
+
def config_root
|
11
|
+
'app/configs'
|
16
12
|
end
|
17
13
|
end
|
@@ -1,46 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
module Runger
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module Runger::Generators ; end
|
6
|
+
|
7
|
+
class Runger::Generators::ConfigGenerator < Rails::Generators::NamedBase
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
10
|
+
class_option :yml, type: :boolean
|
11
|
+
class_option :app, type: :boolean, default: false
|
12
|
+
argument :parameters, type: :array, default: [], banner: 'param1 param2'
|
13
|
+
|
14
|
+
# check_class_collision suffix: "Config"
|
15
|
+
|
16
|
+
def run_install_if_needed
|
17
|
+
return if ::Rails.root.join(static_config_root, 'application_config.rb').exist?
|
18
|
+
|
19
|
+
generate('runger:install')
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_config
|
23
|
+
template('config.rb', File.join(config_root, class_path, "#{file_name}_config.rb"))
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_yml
|
27
|
+
create_yml =
|
28
|
+
options.fetch(:yml) {
|
29
|
+
yes?("Would you like to generate a #{file_name}.yml file?")
|
30
|
+
}
|
31
|
+
return unless create_yml
|
32
|
+
|
33
|
+
template('config.yml', File.join('config', "#{file_name}.yml"))
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def static_config_root
|
39
|
+
Runger::Settings.autoload_static_config_path || Runger::DEFAULT_CONFIGS_PATH
|
40
|
+
end
|
41
|
+
|
42
|
+
def config_root
|
43
|
+
if options[:app]
|
44
|
+
'app/configs'
|
45
|
+
else
|
46
|
+
static_config_root
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -1,47 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
module Runger
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module Runger::Generators ; end
|
6
|
+
|
7
|
+
class Runger::Generators::InstallGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
10
|
+
class_option :configs_path, type: :string
|
11
|
+
|
12
|
+
def copy_application_config
|
13
|
+
template('application_config.rb', File.join(static_config_root, 'application_config.rb'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_local_files_to_gitignore
|
17
|
+
if File.exist?(File.join(destination_root, '.gitignore'))
|
18
|
+
append_to_file('.gitignore', "\n/config/*.local.yml\n/config/credentials/local.*\n")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# rubocop:disable Layout/HeredocIndentation
|
23
|
+
def add_setup_autoload_to_config
|
24
|
+
maybe_comment_indented = default_configs_path? ? ' # ' : ' '
|
25
|
+
inject_into_file('config/application.rb', after: %r{< Rails::Application\n}) do
|
26
|
+
<<-RUBY
|
27
27
|
# Configure the path for configuration classes that should be used before initialization
|
28
28
|
# NOTE: path should be relative to the project root (Rails.root)
|
29
29
|
#{maybe_comment_indented}config.runger_config.autoload_static_config_path = "#{static_config_root}"
|
30
|
-
#{maybe_comment_indented.sub(/\s+$/,
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
#{maybe_comment_indented.sub(/\s+$/, '')}
|
31
|
+
RUBY
|
32
|
+
end
|
33
|
+
end
|
34
|
+
# rubocop:enable Layout/HeredocIndentation
|
35
35
|
|
36
|
-
|
36
|
+
private
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
def static_config_root
|
39
|
+
options[:configs_path] || Runger::Settings.autoload_static_config_path || Runger::DEFAULT_CONFIGS_PATH
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
42
|
+
def default_configs_path?
|
43
|
+
static_config_root == (Runger::Settings.autoload_static_config_path || Runger::DEFAULT_CONFIGS_PATH)
|
46
44
|
end
|
47
45
|
end
|
data/lib/runger/auto_cast.rb
CHANGED
@@ -23,11 +23,11 @@ module Runger
|
|
23
23
|
when /\A(nil|null)\z/i
|
24
24
|
nil
|
25
25
|
when /\A\d+\z/
|
26
|
-
val
|
26
|
+
Integer(val, 10)
|
27
27
|
when /\A\d*\.\d+\z/
|
28
|
-
val
|
28
|
+
Float(val)
|
29
29
|
when /\A['"].*['"]\z/
|
30
|
-
val.gsub(/(\A['"]|['"]\z)/,
|
30
|
+
val.gsub(/(\A['"]|['"]\z)/, '')
|
31
31
|
else
|
32
32
|
val
|
33
33
|
end
|
data/lib/runger/config.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'runger/dynamic_config'
|
5
|
+
require 'runger/optparse_config'
|
6
6
|
|
7
7
|
module Runger # :nodoc:
|
8
8
|
using Runger::Ext::DeepDup
|
@@ -20,6 +20,8 @@ module Runger # :nodoc:
|
|
20
20
|
# Provides `attr_config` method to describe
|
21
21
|
# configuration parameters and set defaults
|
22
22
|
class Config
|
23
|
+
include OptparseConfig
|
24
|
+
include DynamicConfig
|
23
25
|
PARAM_NAME = /^[a-z_](\w+)?$/
|
24
26
|
|
25
27
|
# List of names that couldn't be used as config names
|
@@ -53,9 +55,6 @@ module Runger # :nodoc:
|
|
53
55
|
|
54
56
|
class ValidationError < Error; end
|
55
57
|
|
56
|
-
include OptparseConfig
|
57
|
-
include DynamicConfig
|
58
|
-
|
59
58
|
class BlockCallback
|
60
59
|
attr_reader :block
|
61
60
|
|
@@ -83,17 +82,18 @@ module Runger # :nodoc:
|
|
83
82
|
new_defaults = hargs.deep_dup
|
84
83
|
new_defaults.stringify_keys!
|
85
84
|
|
86
|
-
defaults.merge!
|
85
|
+
defaults.merge!(new_defaults)
|
87
86
|
|
88
87
|
new_keys = ((args + new_defaults.keys) - config_attributes)
|
89
88
|
|
90
|
-
validate_param_names!
|
89
|
+
validate_param_names!(new_keys.map(&:to_s))
|
91
90
|
|
92
91
|
new_keys.map!(&:to_sym)
|
93
92
|
|
94
93
|
unless (reserved_names = (new_keys & RESERVED_NAMES)).empty?
|
95
|
-
raise
|
96
|
-
|
94
|
+
raise(ArgumentError,
|
95
|
+
'Can not use the following reserved names as config attrubutes: ' \
|
96
|
+
"#{reserved_names.sort.map(&:to_s).join(', ')}")
|
97
97
|
end
|
98
98
|
|
99
99
|
config_attributes.push(*new_keys)
|
@@ -104,33 +104,39 @@ module Runger # :nodoc:
|
|
104
104
|
# having `true` or `false` as default values
|
105
105
|
new_defaults.each do |key, val|
|
106
106
|
next unless val.is_a?(TrueClass) || val.is_a?(FalseClass)
|
107
|
-
|
107
|
+
|
108
|
+
alias_method(:"#{key}?", :"#{key}")
|
108
109
|
end
|
109
110
|
end
|
110
111
|
|
111
112
|
def defaults
|
112
113
|
return @defaults if instance_variable_defined?(:@defaults)
|
113
114
|
|
114
|
-
@defaults =
|
115
|
-
superclass
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
@defaults =
|
116
|
+
if superclass < Runger::Config
|
117
|
+
superclass.defaults.deep_dup
|
118
|
+
else
|
119
|
+
new_empty_config
|
120
|
+
end
|
119
121
|
end
|
120
122
|
|
121
123
|
def config_attributes
|
122
124
|
return @config_attributes if instance_variable_defined?(:@config_attributes)
|
123
125
|
|
124
|
-
@config_attributes =
|
125
|
-
superclass
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
@config_attributes =
|
127
|
+
if superclass < Runger::Config
|
128
|
+
superclass.config_attributes.dup
|
129
|
+
else
|
130
|
+
[]
|
131
|
+
end
|
129
132
|
end
|
130
133
|
|
131
134
|
def required(*names, env: nil, **nested)
|
132
135
|
unknown_names = names + nested.keys - config_attributes
|
133
|
-
|
136
|
+
if unknown_names.any?
|
137
|
+
raise(ArgumentError,
|
138
|
+
"Unknown config param: #{unknown_names.join(',')}")
|
139
|
+
end
|
134
140
|
|
135
141
|
return unless Settings.matching_env?(env)
|
136
142
|
|
@@ -141,15 +147,19 @@ module Runger # :nodoc:
|
|
141
147
|
def required_attributes
|
142
148
|
return @required_attributes if instance_variable_defined?(:@required_attributes)
|
143
149
|
|
144
|
-
@required_attributes =
|
145
|
-
superclass
|
146
|
-
|
147
|
-
|
148
|
-
|
150
|
+
@required_attributes =
|
151
|
+
if superclass < Runger::Config
|
152
|
+
superclass.required_attributes.dup
|
153
|
+
else
|
154
|
+
[]
|
155
|
+
end
|
149
156
|
end
|
150
157
|
|
151
158
|
def on_load(*names, &block)
|
152
|
-
|
159
|
+
if block && !names.empty?
|
160
|
+
raise(ArgumentError,
|
161
|
+
'Either methods or block should be specified, not both')
|
162
|
+
end
|
153
163
|
|
154
164
|
if block
|
155
165
|
load_callbacks << BlockCallback.new(block)
|
@@ -161,11 +171,12 @@ module Runger # :nodoc:
|
|
161
171
|
def load_callbacks
|
162
172
|
return @load_callbacks if instance_variable_defined?(:@load_callbacks)
|
163
173
|
|
164
|
-
@load_callbacks =
|
165
|
-
superclass
|
166
|
-
|
167
|
-
|
168
|
-
|
174
|
+
@load_callbacks =
|
175
|
+
if superclass <= Runger::Config
|
176
|
+
superclass.load_callbacks.dup
|
177
|
+
else
|
178
|
+
[]
|
179
|
+
end
|
169
180
|
end
|
170
181
|
|
171
182
|
def config_name(val = nil)
|
@@ -192,11 +203,12 @@ module Runger # :nodoc:
|
|
192
203
|
|
193
204
|
return @env_prefix if instance_variable_defined?(:@env_prefix)
|
194
205
|
|
195
|
-
@env_prefix =
|
196
|
-
superclass.
|
197
|
-
|
198
|
-
|
199
|
-
|
206
|
+
@env_prefix =
|
207
|
+
if superclass < Runger::Config && superclass.explicit_config_name?
|
208
|
+
superclass.env_prefix
|
209
|
+
else
|
210
|
+
config_name.upcase
|
211
|
+
end
|
200
212
|
end
|
201
213
|
|
202
214
|
def loader_options(val = nil)
|
@@ -204,34 +216,36 @@ module Runger # :nodoc:
|
|
204
216
|
|
205
217
|
return @loader_options if instance_variable_defined?(:@loader_options)
|
206
218
|
|
207
|
-
@loader_options =
|
208
|
-
superclass
|
209
|
-
|
210
|
-
|
211
|
-
|
219
|
+
@loader_options =
|
220
|
+
if superclass < Runger::Config
|
221
|
+
superclass.loader_options
|
222
|
+
else
|
223
|
+
{}
|
224
|
+
end
|
212
225
|
end
|
213
226
|
|
214
227
|
def new_empty_config = {}
|
215
228
|
|
216
229
|
def coerce_types(mapping)
|
217
|
-
Utils.deep_merge!(coercion_mapping, mapping)
|
230
|
+
::Runger::Utils.deep_merge!(coercion_mapping, mapping)
|
218
231
|
|
219
232
|
mapping.each do |key, val|
|
220
233
|
type = val.is_a?(::Hash) ? val[:type] : val
|
221
234
|
next if type != :boolean
|
222
235
|
|
223
|
-
alias_method
|
236
|
+
alias_method(:"#{key}?", :"#{key}")
|
224
237
|
end
|
225
238
|
end
|
226
239
|
|
227
240
|
def coercion_mapping
|
228
241
|
return @coercion_mapping if instance_variable_defined?(:@coercion_mapping)
|
229
242
|
|
230
|
-
@coercion_mapping =
|
231
|
-
superclass
|
232
|
-
|
233
|
-
|
234
|
-
|
243
|
+
@coercion_mapping =
|
244
|
+
if superclass < Runger::Config
|
245
|
+
superclass.coercion_mapping.deep_dup
|
246
|
+
else
|
247
|
+
{}
|
248
|
+
end
|
235
249
|
end
|
236
250
|
|
237
251
|
def type_caster(val = nil)
|
@@ -250,11 +264,12 @@ module Runger # :nodoc:
|
|
250
264
|
|
251
265
|
return @fallback_type_caster if instance_variable_defined?(:@fallback_type_caster)
|
252
266
|
|
253
|
-
@fallback_type_caster =
|
254
|
-
superclass
|
255
|
-
|
256
|
-
|
257
|
-
|
267
|
+
@fallback_type_caster =
|
268
|
+
if superclass < Runger::Config
|
269
|
+
superclass.fallback_type_caster.deep_dup
|
270
|
+
else
|
271
|
+
::Runger::AutoCast
|
272
|
+
end
|
258
273
|
end
|
259
274
|
|
260
275
|
def disable_auto_cast!
|
@@ -265,7 +280,7 @@ module Runger # :nodoc:
|
|
265
280
|
|
266
281
|
def define_config_accessor(*names)
|
267
282
|
names.each do |name|
|
268
|
-
accessors_module.module_eval
|
283
|
+
accessors_module.module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
269
284
|
def #{name}=(val)
|
270
285
|
__trace__&.record_value(val, "#{name}", **Tracing.current_trace_source)
|
271
286
|
values[:#{name}] = val
|
@@ -281,31 +296,33 @@ module Runger # :nodoc:
|
|
281
296
|
def accessors_module
|
282
297
|
return @accessors_module if instance_variable_defined?(:@accessors_module)
|
283
298
|
|
284
|
-
@accessors_module =
|
285
|
-
|
286
|
-
|
299
|
+
@accessors_module =
|
300
|
+
Module.new.tap do |mod|
|
301
|
+
include mod
|
302
|
+
end
|
287
303
|
end
|
288
304
|
|
289
305
|
def build_config_name
|
290
306
|
unless name
|
291
|
-
raise
|
292
|
-
|
307
|
+
raise('Please, specify config name explicitly for anonymous class ' \
|
308
|
+
'via `config_name :my_config`')
|
293
309
|
end
|
294
310
|
|
295
|
-
unless name.underscore.
|
296
|
-
raise
|
297
|
-
|
311
|
+
unless name.underscore.tr('/', '_') =~ /(\w+)_config\z/
|
312
|
+
raise("Couldn't infer config name, please, specify it explicitly " \
|
313
|
+
'via `config_name :my_config`')
|
298
314
|
end
|
299
315
|
|
300
|
-
Regexp.last_match[1].delete_suffix(
|
316
|
+
Regexp.last_match[1].delete_suffix('_config').tap(&:downcase!)
|
301
317
|
end
|
302
318
|
|
303
319
|
def validate_param_names!(names)
|
304
|
-
invalid_names = names.
|
320
|
+
invalid_names = names.grep_v(PARAM_NAME)
|
305
321
|
return if invalid_names.empty?
|
306
322
|
|
307
|
-
raise
|
308
|
-
"
|
323
|
+
raise(ArgumentError,
|
324
|
+
"Invalid attr_config name: #{invalid_names.join(', ')}.\n" \
|
325
|
+
"Valid names must satisfy /#{PARAM_NAME.source}/.")
|
309
326
|
end
|
310
327
|
end
|
311
328
|
|
@@ -325,7 +342,7 @@ module Runger # :nodoc:
|
|
325
342
|
def initialize(overrides = nil)
|
326
343
|
@config_name = self.class.config_name
|
327
344
|
|
328
|
-
raise
|
345
|
+
raise(ArgumentError, 'Config name is missing') unless @config_name
|
329
346
|
|
330
347
|
@env_prefix = self.class.env_prefix
|
331
348
|
@values = {}
|
@@ -348,25 +365,26 @@ module Runger # :nodoc:
|
|
348
365
|
def load(overrides = nil)
|
349
366
|
base_config = self.class.defaults.deep_dup
|
350
367
|
|
351
|
-
trace =
|
352
|
-
Tracing.
|
368
|
+
trace =
|
369
|
+
Tracing.capture do
|
370
|
+
Tracing.trace!(:defaults) { base_config }
|
353
371
|
|
354
|
-
|
372
|
+
config_path = resolve_config_path(config_name, env_prefix)
|
355
373
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
374
|
+
load_from_sources(
|
375
|
+
base_config,
|
376
|
+
name: config_name,
|
377
|
+
env_prefix:,
|
378
|
+
config_path:,
|
379
|
+
**self.class.loader_options,
|
380
|
+
)
|
363
381
|
|
364
|
-
|
365
|
-
|
382
|
+
if overrides
|
383
|
+
Tracing.trace!(:load) { overrides }
|
366
384
|
|
367
|
-
|
385
|
+
::Runger::Utils.deep_merge!(base_config, overrides)
|
386
|
+
end
|
368
387
|
end
|
369
|
-
end
|
370
388
|
|
371
389
|
base_config.each do |key, val|
|
372
390
|
write_config_attr(key.to_sym, val)
|
@@ -385,9 +403,9 @@ module Runger # :nodoc:
|
|
385
403
|
self
|
386
404
|
end
|
387
405
|
|
388
|
-
def load_from_sources(base_config, **)
|
406
|
+
def load_from_sources(base_config, **options)
|
389
407
|
Runger.loaders.each do |(_id, loader)|
|
390
|
-
Utils.deep_merge!(base_config, loader.call(**))
|
408
|
+
::Runger::Utils.deep_merge!(base_config, loader.call(**options))
|
391
409
|
end
|
392
410
|
base_config
|
393
411
|
end
|
@@ -406,7 +424,7 @@ module Runger # :nodoc:
|
|
406
424
|
end
|
407
425
|
|
408
426
|
def resolve_config_path(name, env_prefix)
|
409
|
-
Runger.env.fetch(env_prefix).delete(
|
427
|
+
Runger.env.fetch(env_prefix).delete('conf') || Settings.default_config_path.call(name)
|
410
428
|
end
|
411
429
|
|
412
430
|
def deconstruct_keys(keys) = values.deconstruct_keys(keys)
|
@@ -414,20 +432,21 @@ module Runger # :nodoc:
|
|
414
432
|
def to_source_trace = __trace__&.to_h
|
415
433
|
|
416
434
|
def inspect
|
417
|
-
"#<#{self.class}:0x#{vm_object_id.rjust(16,
|
418
|
-
|
435
|
+
"#<#{self.class}:0x#{vm_object_id.rjust(16,
|
436
|
+
'0')} config_name=\"#{config_name}\" env_prefix=\"#{env_prefix}\" " \
|
437
|
+
"values=#{values.inspect}>"
|
419
438
|
end
|
420
439
|
|
421
440
|
def pretty_print(q)
|
422
|
-
q.object_group
|
441
|
+
q.object_group(self) do
|
423
442
|
q.nest(1) do
|
424
443
|
q.breakable
|
425
444
|
q.text "config_name=#{config_name.inspect}"
|
426
445
|
q.breakable
|
427
446
|
q.text "env_prefix=#{env_prefix.inspect}"
|
428
447
|
q.breakable
|
429
|
-
q.text
|
430
|
-
q.pp
|
448
|
+
q.text 'values:'
|
449
|
+
q.pp(__trace__)
|
431
450
|
end
|
432
451
|
end
|
433
452
|
end
|
@@ -442,11 +461,12 @@ module Runger # :nodoc:
|
|
442
461
|
|
443
462
|
def validate_required_attributes!
|
444
463
|
self.class.required_attributes.select do |name|
|
445
|
-
val = values.dig(*name.to_s.split(
|
464
|
+
val = values.dig(*name.to_s.split('.').map(&:to_sym))
|
446
465
|
val.nil? || (val.is_a?(String) && val.empty?)
|
447
466
|
end.then do |missing|
|
448
467
|
next if missing.empty?
|
449
|
-
|
468
|
+
|
469
|
+
raise_validation_error("The following config parameters for `#{self.class.name}(config_name: #{self.class.config_name})` are missing or empty: #{missing.join(', ')}")
|
450
470
|
end
|
451
471
|
end
|
452
472
|
|
@@ -459,7 +479,7 @@ module Runger # :nodoc:
|
|
459
479
|
end
|
460
480
|
|
461
481
|
def raise_validation_error(msg)
|
462
|
-
raise
|
482
|
+
raise(ValidationError, msg)
|
463
483
|
end
|
464
484
|
|
465
485
|
def __type_caster__
|