runger_config 4.0.0 → 5.1.0
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 +8 -0
- data/bin/release +27 -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 +20 -19
@@ -1,35 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
class Secrets < Runger::Loaders::Base
|
7
|
-
def call(name:, **_options)
|
8
|
-
return {} unless ::Rails.application.respond_to?(:secrets)
|
3
|
+
class Runger::Rails::Loaders::Secrets < Runger::Loaders::Base
|
4
|
+
def call(name:, **_options)
|
5
|
+
return {} unless ::Rails.application.respond_to?(:secrets)
|
9
6
|
|
10
|
-
|
11
|
-
|
7
|
+
# Create a new hash cause secrets are mutable!
|
8
|
+
config = {}
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
trace!(:secrets) do
|
11
|
+
secrets.public_send(name)
|
12
|
+
end.then do |secrets|
|
13
|
+
::Runger::Utils.deep_merge!(config, secrets) if secrets
|
14
|
+
end
|
15
|
+
|
16
|
+
config
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
end
|
19
|
+
private
|
21
20
|
|
22
|
-
|
21
|
+
def secrets
|
22
|
+
@secrets ||=
|
23
|
+
::Rails.application.secrets.tap do |_|
|
24
|
+
# Reset secrets state if the app hasn't been initialized
|
25
|
+
# See https://github.com/palkan/runger_config/issues/14
|
26
|
+
next if ::Rails.application.initialized?
|
23
27
|
|
24
|
-
|
25
|
-
@secrets ||= ::Rails.application.secrets.tap do |_|
|
26
|
-
# Reset secrets state if the app hasn't been initialized
|
27
|
-
# See https://github.com/palkan/runger_config/issues/14
|
28
|
-
next if ::Rails.application.initialized?
|
29
|
-
::Rails.application.remove_instance_variable(:@secrets)
|
30
|
-
end
|
31
|
-
end
|
28
|
+
::Rails.application.remove_instance_variable(:@secrets)
|
32
29
|
end
|
33
|
-
end
|
34
30
|
end
|
35
31
|
end
|
data/lib/runger/rails/loaders.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'runger/rails/loaders/credentials'
|
4
|
+
require 'runger/rails/loaders/secrets'
|
5
|
+
require 'runger/rails/loaders/yaml'
|
@@ -2,33 +2,33 @@
|
|
2
2
|
|
3
3
|
# Try to require zeitwerk
|
4
4
|
begin
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require 'active_support/dependencies/zeitwerk_integration'
|
6
|
+
require 'zeitwerk'
|
7
7
|
rescue LoadError
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
class
|
12
|
-
|
13
|
-
|
14
|
-
attr_writer :autoload_via_zeitwerk
|
10
|
+
class Runger::Settings
|
11
|
+
class << self
|
12
|
+
attr_reader :autoload_static_config_path, :autoloader
|
13
|
+
attr_writer :autoload_via_zeitwerk
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def autoload_static_config_path=(val)
|
16
|
+
if autoload_via_zeitwerk
|
17
|
+
raise('Cannot setup autoloader after application has been initialized') if ::Rails.application.initialized?
|
19
18
|
|
20
|
-
|
19
|
+
return unless ::Rails.root.join(val).exist?
|
21
20
|
|
22
|
-
|
21
|
+
return if val == autoload_static_config_path
|
23
22
|
|
24
|
-
|
23
|
+
autoloader&.unload
|
25
24
|
|
26
|
-
|
25
|
+
@autoload_static_config_path = val
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
# See Rails 6 https://github.com/rails/rails/blob/8ab4fd12f18203b83d0f252db96d10731485ff6a/railties/lib/rails/autoloaders.rb#L10
|
28
|
+
# and Rails 7 https://github.com/rails/rails/blob/5462fbd5de1900c1b1ce1c9dc11c1a2d8cdcd809/railties/lib/rails/autoloaders.rb#L15
|
29
|
+
@autoloader =
|
30
|
+
Zeitwerk::Loader.new.tap do |loader|
|
31
|
+
loader.tag = 'runger.config'
|
32
32
|
|
33
33
|
if defined?(ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector)
|
34
34
|
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
@@ -38,46 +38,46 @@ module Runger
|
|
38
38
|
loader.push_dir(::Rails.root.join(val))
|
39
39
|
loader.setup
|
40
40
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
@autoload_static_config_path = val
|
49
|
-
new_path = ::Rails.root.join(val).to_s
|
50
|
-
ActiveSupport::Dependencies.autoload_paths << new_path
|
51
|
-
::Rails.application.config.eager_load_paths << new_path
|
41
|
+
else
|
42
|
+
if autoload_static_config_path
|
43
|
+
old_path = ::Rails.root.join(autoload_static_config_path).to_s
|
44
|
+
ActiveSupport::Dependencies.autoload_paths.delete(old_path)
|
45
|
+
::Rails.application.config.eager_load_paths.delete(old_path)
|
52
46
|
end
|
47
|
+
|
48
|
+
@autoload_static_config_path = val
|
49
|
+
new_path = ::Rails.root.join(val).to_s
|
50
|
+
ActiveSupport::Dependencies.autoload_paths << new_path
|
51
|
+
::Rails.application.config.eager_load_paths << new_path
|
53
52
|
end
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
def cleanup_autoload_paths
|
56
|
+
return unless autoload_via_zeitwerk
|
57
57
|
|
58
|
-
|
59
|
-
ActiveSupport::Dependencies.autoload_paths.delete(::Rails.root.join(autoload_static_config_path).to_s)
|
60
|
-
end
|
58
|
+
return unless autoload_static_config_path
|
61
59
|
|
62
|
-
|
63
|
-
|
60
|
+
ActiveSupport::Dependencies.autoload_paths.delete(::Rails.root.join(autoload_static_config_path).to_s)
|
61
|
+
end
|
64
62
|
|
65
|
-
|
66
|
-
|
63
|
+
def autoload_via_zeitwerk
|
64
|
+
return @autoload_via_zeitwerk if instance_variable_defined?(:@autoload_via_zeitwerk)
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
end
|
66
|
+
@autoload_via_zeitwerk = defined?(::Zeitwerk)
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
end
|
69
|
+
def current_environment
|
70
|
+
@current_environment || ::Rails.env.to_s
|
75
71
|
end
|
76
72
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# Don't try read defaults when no key defined
|
81
|
-
self.default_environmental_key = nil
|
73
|
+
def app_root
|
74
|
+
::Rails.root
|
75
|
+
end
|
82
76
|
end
|
77
|
+
|
78
|
+
self.default_config_path = ->(name) { ::Rails.root.join('config', "#{name}.yml") }
|
79
|
+
self.known_environments = %w[test development production]
|
80
|
+
self.use_local_files ||= ::Rails.env.development?
|
81
|
+
# Don't try read defaults when no key defined
|
82
|
+
self.default_environmental_key = nil
|
83
83
|
end
|
data/lib/runger/rails.rb
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Runger
|
4
|
-
module Rails
|
5
|
-
end
|
3
|
+
module Runger::Rails
|
6
4
|
end
|
7
5
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
6
|
+
require 'runger/rails/config'
|
7
|
+
require 'runger/rails/loaders'
|
8
|
+
require 'runger/rails/settings'
|
11
9
|
|
12
10
|
# Configure Rails loaders
|
13
|
-
Runger.loaders.override
|
11
|
+
Runger.loaders.override(:yml, Runger::Rails::Loaders::YAML)
|
14
12
|
|
15
13
|
if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 1
|
16
|
-
Runger.loaders.insert_after
|
14
|
+
Runger.loaders.insert_after(:yml, :credentials, Runger::Rails::Loaders::Credentials)
|
17
15
|
else
|
18
|
-
Runger.loaders.insert_after
|
19
|
-
Runger.loaders.insert_after
|
16
|
+
Runger.loaders.insert_after(:yml, :secrets, Runger::Rails::Loaders::Secrets)
|
17
|
+
Runger.loaders.insert_after(:secrets, :credentials, Runger::Rails::Loaders::Credentials)
|
20
18
|
end
|
21
19
|
|
22
20
|
# Load Railties after configuring loaders.
|
23
21
|
# The application could be already initialized, and that would make `Runger.loaders` frozen
|
24
|
-
require
|
22
|
+
require 'runger/railtie'
|
data/lib/runger/railtie.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Runger # :nodoc:
|
4
|
-
DEFAULT_CONFIGS_PATH =
|
4
|
+
DEFAULT_CONFIGS_PATH = 'config/configs'
|
5
5
|
|
6
6
|
class Railtie < ::Rails::Railtie # :nodoc:
|
7
7
|
# Add settings to Rails config
|
@@ -9,6 +9,7 @@ module Runger # :nodoc:
|
|
9
9
|
|
10
10
|
config.before_configuration do
|
11
11
|
next if ::Rails.application.initialized?
|
12
|
+
|
12
13
|
config.runger_config.autoload_static_config_path = DEFAULT_CONFIGS_PATH
|
13
14
|
end
|
14
15
|
|
@@ -18,7 +19,7 @@ module Runger # :nodoc:
|
|
18
19
|
|
19
20
|
# Remove `autoload_static_config_path` from Rails `autoload_paths`
|
20
21
|
# since we use our own autoloading mechanism
|
21
|
-
initializer
|
22
|
+
initializer 'runger_config.cleanup_autoload' do
|
22
23
|
Runger::Settings.cleanup_autoload_paths
|
23
24
|
end
|
24
25
|
|
data/lib/runger/rbs.rb
CHANGED
@@ -3,33 +3,33 @@
|
|
3
3
|
module Runger
|
4
4
|
module RBSGenerator
|
5
5
|
TYPE_TO_CLASS = {
|
6
|
-
string:
|
7
|
-
integer:
|
8
|
-
float:
|
9
|
-
date:
|
10
|
-
datetime:
|
11
|
-
uri:
|
12
|
-
boolean:
|
6
|
+
string: 'String',
|
7
|
+
integer: 'Integer',
|
8
|
+
float: 'Float',
|
9
|
+
date: 'Date',
|
10
|
+
datetime: 'DateTime',
|
11
|
+
uri: 'URI',
|
12
|
+
boolean: 'bool',
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
# Generate RBS signature from a config class
|
16
16
|
def to_rbs
|
17
|
-
*namespace, class_name = name.split(
|
17
|
+
*namespace, class_name = name.split('::')
|
18
18
|
|
19
19
|
buf = []
|
20
20
|
indent = 0
|
21
|
-
interface_name =
|
21
|
+
interface_name = '_Config'
|
22
22
|
|
23
23
|
if namespace.empty?
|
24
24
|
interface_name = "_#{class_name}"
|
25
25
|
else
|
26
|
-
buf << "module #{namespace.join(
|
26
|
+
buf << "module #{namespace.join('::')}"
|
27
27
|
indent += 1
|
28
28
|
end
|
29
29
|
|
30
30
|
# Using interface emulates a module we include to provide getters and setters
|
31
31
|
# (thus making `super` possible)
|
32
|
-
buf << "#{
|
32
|
+
buf << "#{' ' * indent}interface #{interface_name}"
|
33
33
|
indent += 1
|
34
34
|
|
35
35
|
# Generating setters and getters for config attributes
|
@@ -39,17 +39,17 @@ module Runger
|
|
39
39
|
type =
|
40
40
|
case type
|
41
41
|
in NilClass
|
42
|
-
|
42
|
+
'untyped'
|
43
43
|
in Symbol
|
44
|
-
TYPE_TO_CLASS.fetch(type) { defaults[param] ?
|
44
|
+
TYPE_TO_CLASS.fetch(type) { defaults[param] ? 'Symbol' : 'untyped' }
|
45
45
|
in Array
|
46
|
-
|
46
|
+
'Array[untyped]'
|
47
47
|
in array: _, type:, **nil
|
48
|
-
"Array[#{TYPE_TO_CLASS.fetch(type,
|
48
|
+
"Array[#{TYPE_TO_CLASS.fetch(type, 'untyped')}]"
|
49
49
|
in Hash
|
50
|
-
|
50
|
+
'Hash[string,untyped]'
|
51
51
|
in TrueClass | FalseClass
|
52
|
-
|
52
|
+
'bool'
|
53
53
|
else
|
54
54
|
type.class.to_s
|
55
55
|
end
|
@@ -57,36 +57,36 @@ module Runger
|
|
57
57
|
getter_type = type
|
58
58
|
getter_type = "#{type}?" unless required_attributes.include?(param)
|
59
59
|
|
60
|
-
buf << "#{
|
61
|
-
buf << "#{
|
60
|
+
buf << "#{' ' * indent}def #{param}: () -> #{getter_type}"
|
61
|
+
buf << "#{' ' * indent}def #{param}=: (#{type}) -> void"
|
62
62
|
|
63
|
-
if
|
64
|
-
buf << "#{
|
63
|
+
if ['bool', 'bool?'].include?(type)
|
64
|
+
buf << "#{' ' * indent}def #{param}?: () -> #{getter_type}"
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
indent -= 1
|
69
|
-
buf << "#{
|
69
|
+
buf << "#{' ' * indent}end"
|
70
70
|
|
71
|
-
buf <<
|
71
|
+
buf << ''
|
72
72
|
|
73
|
-
buf << "#{
|
73
|
+
buf << "#{' ' * indent}class #{class_name} < #{superclass.name}"
|
74
74
|
indent += 1
|
75
75
|
|
76
|
-
buf << "#{
|
76
|
+
buf << "#{' ' * indent}include #{interface_name}"
|
77
77
|
|
78
78
|
indent -= 1
|
79
|
-
buf << "#{
|
79
|
+
buf << "#{' ' * indent}end"
|
80
80
|
|
81
81
|
unless namespace.empty?
|
82
|
-
buf <<
|
82
|
+
buf << 'end'
|
83
83
|
end
|
84
84
|
|
85
|
-
buf <<
|
85
|
+
buf << ''
|
86
86
|
|
87
87
|
buf.join("\n")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
Config.extend
|
91
|
+
Config.extend(RBSGenerator)
|
92
92
|
end
|
data/lib/runger/settings.rb
CHANGED
@@ -1,111 +1,109 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
class
|
13
|
-
|
14
|
-
|
15
|
-
settings[name] = default_value
|
16
|
-
|
17
|
-
define_method(name) do
|
18
|
-
store[name]
|
19
|
-
end
|
20
|
-
|
21
|
-
define_method(:"#{name}=") do |val|
|
22
|
-
store[name] = val
|
23
|
-
end
|
24
|
-
end
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# Use Settings name to not confuse with Config.
|
6
|
+
#
|
7
|
+
# Settings contain the library-wide configuration.
|
8
|
+
class Runger::Settings
|
9
|
+
# Future encapsulates settings that will be introduced in the upcoming version
|
10
|
+
# with the default values, which could break compatibility
|
11
|
+
class Future
|
12
|
+
class << self
|
13
|
+
def setting(name, default_value)
|
14
|
+
settings[name] = default_value
|
25
15
|
|
26
|
-
|
27
|
-
|
16
|
+
define_method(name) do
|
17
|
+
store[name]
|
28
18
|
end
|
29
|
-
end
|
30
19
|
|
31
|
-
|
32
|
-
|
20
|
+
define_method(:"#{name}=") do |val|
|
21
|
+
store[name] = val
|
22
|
+
end
|
33
23
|
end
|
34
24
|
|
35
|
-
def
|
36
|
-
|
37
|
-
names.each { store[_1] = self.class.settings[_1] }
|
25
|
+
def settings
|
26
|
+
@settings ||= {}
|
38
27
|
end
|
28
|
+
end
|
39
29
|
|
40
|
-
|
41
|
-
|
42
|
-
|
30
|
+
def initialize
|
31
|
+
@store = {}
|
32
|
+
end
|
43
33
|
|
44
|
-
|
34
|
+
def use(*names)
|
35
|
+
store.clear
|
36
|
+
names.each { store[_1] = self.class.settings[_1] }
|
45
37
|
end
|
46
38
|
|
47
|
-
|
48
|
-
# Define whether to load data from
|
49
|
-
# *.yml.local (or credentials/local.yml.enc)
|
50
|
-
attr_accessor :use_local_files,
|
51
|
-
:current_environment,
|
52
|
-
:default_environmental_key,
|
53
|
-
:known_environments
|
54
|
-
|
55
|
-
# A proc returning a path to YML config file given the config name
|
56
|
-
attr_reader :default_config_path
|
57
|
-
|
58
|
-
def default_config_path=(val)
|
59
|
-
if val.is_a?(Proc)
|
60
|
-
@default_config_path = val
|
61
|
-
return
|
62
|
-
end
|
39
|
+
setting :unwrap_known_environments, true
|
63
40
|
|
64
|
-
|
41
|
+
private
|
65
42
|
|
66
|
-
|
43
|
+
attr_reader :store
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
# Define whether to load data from
|
48
|
+
# *.yml.local (or credentials/local.yml.enc)
|
49
|
+
attr_accessor :use_local_files,
|
50
|
+
:current_environment,
|
51
|
+
:default_environmental_key,
|
52
|
+
:known_environments
|
53
|
+
|
54
|
+
# A proc returning a path to YML config file given the config name
|
55
|
+
attr_reader :default_config_path
|
56
|
+
|
57
|
+
def default_config_path=(val)
|
58
|
+
if val.is_a?(Proc)
|
59
|
+
@default_config_path = val
|
60
|
+
return
|
67
61
|
end
|
68
62
|
|
69
|
-
|
70
|
-
attr_accessor :tracing_enabled
|
63
|
+
val = val.to_s
|
71
64
|
|
72
|
-
|
73
|
-
|
74
|
-
end
|
65
|
+
@default_config_path = ->(name) { File.join(val, "#{name}.yml") }
|
66
|
+
end
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
end
|
68
|
+
# Enable source tracing
|
69
|
+
attr_accessor :tracing_enabled
|
79
70
|
|
80
|
-
|
81
|
-
|
82
|
-
|
71
|
+
def future
|
72
|
+
@future ||= Future.new
|
73
|
+
end
|
83
74
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
75
|
+
def app_root
|
76
|
+
Pathname.new(Dir.pwd)
|
77
|
+
end
|
78
|
+
|
79
|
+
def default_environmental_key?
|
80
|
+
!default_environmental_key.nil?
|
81
|
+
end
|
82
|
+
|
83
|
+
def matching_env?(env)
|
84
|
+
return true if env.nil? || env.to_s == current_environment
|
85
|
+
|
86
|
+
if env.is_a?(::Hash)
|
87
|
+
envs = env[:except]
|
88
|
+
excluded_envs = [envs].flat_map(&:to_s)
|
89
|
+
excluded_envs.none?(current_environment)
|
90
|
+
elsif env.is_a?(::Array)
|
91
|
+
env.flat_map(&:to_s).include?(current_environment)
|
92
|
+
else
|
93
|
+
false
|
96
94
|
end
|
97
95
|
end
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
98
|
+
# By default, use RUNGER_ENV
|
99
|
+
self.current_environment = ENV.fetch('RUNGER_ENV', nil)
|
101
100
|
|
102
|
-
|
103
|
-
|
101
|
+
# By default, use local files only in development (that's the purpose if the local files)
|
102
|
+
self.use_local_files = (ENV['RUNGER_ENV'] == 'development' || ENV['RACK_ENV'] == 'development' || ENV['RAILS_ENV'] == 'development' || (defined?(Rails) && Rails.env.development?))
|
104
103
|
|
105
|
-
|
106
|
-
|
104
|
+
# By default, consider configs are stored in the ./config folder
|
105
|
+
self.default_config_path = ->(name) { "./config/#{name}.yml" }
|
107
106
|
|
108
|
-
|
109
|
-
|
110
|
-
end
|
107
|
+
# Tracing is enabled by default
|
108
|
+
self.tracing_enabled = true
|
111
109
|
end
|
@@ -1,36 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Runger
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def with_env(data)
|
14
|
-
was_values = []
|
3
|
+
module Runger::Testing::Helpers
|
4
|
+
# Sets the ENV variables to the provided
|
5
|
+
# values and restore outside the block
|
6
|
+
#
|
7
|
+
# Also resets Runger.env before and after calling the block
|
8
|
+
# to make sure that the values are not cached.
|
9
|
+
#
|
10
|
+
# NOTE: to remove the env value, pass `nil` as the value
|
11
|
+
def with_env(data)
|
12
|
+
was_values = []
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
ENV[key] = val
|
20
|
-
end
|
14
|
+
data.each do |key, val|
|
15
|
+
was_values << [key, ENV.fetch(key, nil)]
|
16
|
+
next ENV.delete(key) if val.nil?
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
ENV[key] = val
|
19
|
+
end
|
20
|
+
|
21
|
+
# clear cached env values
|
22
|
+
Runger.env.clear
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
was_values.each do |(key, val)|
|
26
|
+
next ENV.delete(key) if val.nil?
|
30
27
|
|
31
|
-
|
32
|
-
Runger.env.clear
|
33
|
-
end
|
28
|
+
ENV[key] = val
|
34
29
|
end
|
30
|
+
|
31
|
+
# clear cache again
|
32
|
+
Runger.env.clear
|
35
33
|
end
|
36
34
|
end
|
data/lib/runger/testing.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'runger/testing/helpers'
|
4
4
|
|
5
5
|
if defined?(RSpec::Core) && RSpec.respond_to?(:configure)
|
6
6
|
RSpec.configure do |config|
|
7
7
|
config.include(
|
8
8
|
Runger::Testing::Helpers,
|
9
9
|
type: :config,
|
10
|
-
file_path: %r{spec/configs}
|
10
|
+
file_path: %r{spec/configs},
|
11
11
|
)
|
12
12
|
end
|
13
13
|
end
|