runger_config 3.0.1 → 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 +44 -35
- data/README.md +83 -83
- data/lib/generators/runger/app_config/app_config_generator.rb +13 -0
- data/lib/generators/runger/config/config_generator.rb +49 -0
- data/lib/generators/runger/install/install_generator.rb +45 -0
- data/lib/generators/{anyway → runger}/install/templates/application_config.rb.tt +1 -1
- data/lib/{anyway → runger}/auto_cast.rb +4 -4
- data/lib/{anyway → runger}/config.rb +124 -104
- data/lib/runger/dynamic_config.rb +29 -0
- data/lib/runger/ejson_parser.rb +40 -0
- data/lib/runger/env.rb +70 -0
- data/lib/runger/ext/deep_dup.rb +45 -0
- data/lib/runger/ext/deep_freeze.rb +40 -0
- data/lib/runger/ext/flatten_names.rb +33 -0
- data/lib/runger/ext/hash.rb +37 -0
- data/lib/runger/ext/string_constantize.rb +21 -0
- data/lib/runger/loaders/base.rb +17 -0
- data/lib/runger/loaders/doppler.rb +57 -0
- data/lib/runger/loaders/ejson.rb +91 -0
- data/lib/runger/loaders/env.rb +12 -0
- data/lib/runger/loaders/yaml.rb +86 -0
- data/lib/runger/loaders.rb +75 -0
- data/lib/runger/option_parser_builder.rb +27 -0
- data/lib/{anyway → runger}/optparse_config.rb +15 -14
- data/lib/runger/rails/autoload.rb +38 -0
- data/lib/runger/rails/config.rb +19 -0
- data/lib/runger/rails/loaders/credentials.rb +58 -0
- data/lib/runger/rails/loaders/secrets.rb +31 -0
- data/lib/runger/rails/loaders/yaml.rb +4 -0
- data/lib/runger/rails/loaders.rb +5 -0
- data/lib/runger/rails/settings.rb +83 -0
- data/lib/runger/rails.rb +22 -0
- data/lib/{anyway → runger}/railtie.rb +9 -8
- data/lib/{anyway → runger}/rbs.rb +30 -30
- data/lib/runger/settings.rb +109 -0
- data/lib/runger/testing/helpers.rb +34 -0
- data/lib/{anyway → runger}/testing.rb +3 -3
- data/lib/runger/tracing.rb +195 -0
- data/lib/{anyway → runger}/type_casting.rb +19 -14
- data/lib/{anyway → runger}/utils/deep_merge.rb +2 -2
- data/lib/runger/utils/which.rb +16 -0
- data/lib/runger/version.rb +5 -0
- data/lib/{anyway.rb → runger.rb} +1 -1
- data/lib/runger_config.rb +56 -0
- data/sig/{anyway_config.rbs → runger_config.rbs} +1 -1
- metadata +68 -68
- data/lib/anyway/dynamic_config.rb +0 -31
- data/lib/anyway/ejson_parser.rb +0 -40
- data/lib/anyway/env.rb +0 -72
- data/lib/anyway/ext/deep_dup.rb +0 -48
- data/lib/anyway/ext/deep_freeze.rb +0 -44
- data/lib/anyway/ext/flatten_names.rb +0 -37
- data/lib/anyway/ext/hash.rb +0 -40
- data/lib/anyway/ext/string_constantize.rb +0 -24
- data/lib/anyway/loaders/base.rb +0 -21
- data/lib/anyway/loaders/doppler.rb +0 -61
- data/lib/anyway/loaders/ejson.rb +0 -89
- data/lib/anyway/loaders/env.rb +0 -16
- data/lib/anyway/loaders/yaml.rb +0 -83
- data/lib/anyway/loaders.rb +0 -77
- data/lib/anyway/option_parser_builder.rb +0 -29
- data/lib/anyway/rails/autoload.rb +0 -40
- data/lib/anyway/rails/config.rb +0 -23
- data/lib/anyway/rails/loaders/credentials.rb +0 -62
- data/lib/anyway/rails/loaders/secrets.rb +0 -35
- data/lib/anyway/rails/loaders/yaml.rb +0 -9
- data/lib/anyway/rails/loaders.rb +0 -5
- data/lib/anyway/rails/settings.rb +0 -83
- data/lib/anyway/rails.rb +0 -24
- data/lib/anyway/settings.rb +0 -111
- data/lib/anyway/testing/helpers.rb +0 -36
- data/lib/anyway/tracing.rb +0 -188
- data/lib/anyway/utils/which.rb +0 -18
- data/lib/anyway/version.rb +0 -5
- data/lib/anyway_config.rb +0 -49
- data/lib/generators/anyway/app_config/app_config_generator.rb +0 -17
- data/lib/generators/anyway/config/config_generator.rb +0 -46
- data/lib/generators/anyway/install/install_generator.rb +0 -47
- /data/lib/generators/{anyway → runger}/app_config/USAGE +0 -0
- /data/lib/generators/{anyway → runger}/config/USAGE +0 -0
- /data/lib/generators/{anyway → runger}/config/templates/config.rb.tt +0 -0
- /data/lib/generators/{anyway → runger}/config/templates/config.yml.tt +0 -0
- /data/lib/generators/{anyway → runger}/install/USAGE +0 -0
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Try to require zeitwerk
|
4
|
-
begin
|
5
|
-
require "zeitwerk"
|
6
|
-
require "active_support/dependencies/zeitwerk_integration"
|
7
|
-
rescue LoadError
|
8
|
-
end
|
9
|
-
|
10
|
-
module Anyway
|
11
|
-
class Settings
|
12
|
-
class << self
|
13
|
-
attr_reader :autoload_static_config_path, :autoloader
|
14
|
-
attr_writer :autoload_via_zeitwerk
|
15
|
-
|
16
|
-
def autoload_static_config_path=(val)
|
17
|
-
if autoload_via_zeitwerk
|
18
|
-
raise "Cannot setup autoloader after application has been initialized" if ::Rails.application.initialized?
|
19
|
-
|
20
|
-
return unless ::Rails.root.join(val).exist?
|
21
|
-
|
22
|
-
return if val == autoload_static_config_path
|
23
|
-
|
24
|
-
autoloader&.unload
|
25
|
-
|
26
|
-
@autoload_static_config_path = val
|
27
|
-
|
28
|
-
# See Rails 6 https://github.com/rails/rails/blob/8ab4fd12f18203b83d0f252db96d10731485ff6a/railties/lib/rails/autoloaders.rb#L10
|
29
|
-
# and Rails 7 https://github.com/rails/rails/blob/5462fbd5de1900c1b1ce1c9dc11c1a2d8cdcd809/railties/lib/rails/autoloaders.rb#L15
|
30
|
-
@autoloader = Zeitwerk::Loader.new.tap do |loader|
|
31
|
-
loader.tag = "anyway.config"
|
32
|
-
|
33
|
-
if defined?(ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector)
|
34
|
-
loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
|
35
|
-
elsif defined?(::Rails::Autoloaders::Inflector)
|
36
|
-
loader.inflector = ::Rails::Autoloaders::Inflector
|
37
|
-
end
|
38
|
-
loader.push_dir(::Rails.root.join(val))
|
39
|
-
loader.setup
|
40
|
-
end
|
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)
|
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
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def cleanup_autoload_paths
|
56
|
-
return unless autoload_via_zeitwerk
|
57
|
-
|
58
|
-
return unless autoload_static_config_path
|
59
|
-
ActiveSupport::Dependencies.autoload_paths.delete(::Rails.root.join(autoload_static_config_path).to_s)
|
60
|
-
end
|
61
|
-
|
62
|
-
def autoload_via_zeitwerk
|
63
|
-
return @autoload_via_zeitwerk if instance_variable_defined?(:@autoload_via_zeitwerk)
|
64
|
-
|
65
|
-
@autoload_via_zeitwerk = defined?(::Zeitwerk)
|
66
|
-
end
|
67
|
-
|
68
|
-
def current_environment
|
69
|
-
@current_environment || ::Rails.env.to_s
|
70
|
-
end
|
71
|
-
|
72
|
-
def app_root
|
73
|
-
::Rails.root
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
self.default_config_path = ->(name) { ::Rails.root.join("config", "#{name}.yml") }
|
78
|
-
self.known_environments = %w[test development production]
|
79
|
-
self.use_local_files ||= ::Rails.env.development?
|
80
|
-
# Don't try read defaults when no key defined
|
81
|
-
self.default_environmental_key = nil
|
82
|
-
end
|
83
|
-
end
|
data/lib/anyway/rails.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Anyway
|
4
|
-
module Rails
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
require "anyway/rails/settings"
|
9
|
-
require "anyway/rails/config"
|
10
|
-
require "anyway/rails/loaders"
|
11
|
-
|
12
|
-
# Configure Rails loaders
|
13
|
-
Anyway.loaders.override :yml, Anyway::Rails::Loaders::YAML
|
14
|
-
|
15
|
-
if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 1
|
16
|
-
Anyway.loaders.insert_after :yml, :credentials, Anyway::Rails::Loaders::Credentials
|
17
|
-
else
|
18
|
-
Anyway.loaders.insert_after :yml, :secrets, Anyway::Rails::Loaders::Secrets
|
19
|
-
Anyway.loaders.insert_after :secrets, :credentials, Anyway::Rails::Loaders::Credentials
|
20
|
-
end
|
21
|
-
|
22
|
-
# Load Railties after configuring loaders.
|
23
|
-
# The application could be already initialized, and that would make `Anyway.loaders` frozen
|
24
|
-
require "anyway/railtie"
|
data/lib/anyway/settings.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "pathname"
|
4
|
-
|
5
|
-
module Anyway
|
6
|
-
# Use Settings name to not confuse with Config.
|
7
|
-
#
|
8
|
-
# Settings contain the library-wide configuration.
|
9
|
-
class Settings
|
10
|
-
# Future encapsulates settings that will be introduced in the upcoming version
|
11
|
-
# with the default values, which could break compatibility
|
12
|
-
class Future
|
13
|
-
class << self
|
14
|
-
def setting(name, default_value)
|
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
|
25
|
-
|
26
|
-
def settings
|
27
|
-
@settings ||= {}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize
|
32
|
-
@store = {}
|
33
|
-
end
|
34
|
-
|
35
|
-
def use(*names)
|
36
|
-
store.clear
|
37
|
-
names.each { store[_1] = self.class.settings[_1] }
|
38
|
-
end
|
39
|
-
|
40
|
-
setting :unwrap_known_environments, true
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
attr_reader :store
|
45
|
-
end
|
46
|
-
|
47
|
-
class << self
|
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
|
63
|
-
|
64
|
-
val = val.to_s
|
65
|
-
|
66
|
-
@default_config_path = ->(name) { File.join(val, "#{name}.yml") }
|
67
|
-
end
|
68
|
-
|
69
|
-
# Enable source tracing
|
70
|
-
attr_accessor :tracing_enabled
|
71
|
-
|
72
|
-
def future
|
73
|
-
@future ||= Future.new
|
74
|
-
end
|
75
|
-
|
76
|
-
def app_root
|
77
|
-
Pathname.new(Dir.pwd)
|
78
|
-
end
|
79
|
-
|
80
|
-
def default_environmental_key?
|
81
|
-
!default_environmental_key.nil?
|
82
|
-
end
|
83
|
-
|
84
|
-
def matching_env?(env)
|
85
|
-
return true if env.nil? || env.to_s == current_environment
|
86
|
-
|
87
|
-
if env.is_a?(::Hash)
|
88
|
-
envs = env[:except]
|
89
|
-
excluded_envs = [envs].flat_map(&:to_s)
|
90
|
-
excluded_envs.none?(current_environment)
|
91
|
-
elsif env.is_a?(::Array)
|
92
|
-
env.flat_map(&:to_s).include?(current_environment)
|
93
|
-
else
|
94
|
-
false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# By default, use ANYWAY_ENV
|
100
|
-
self.current_environment = ENV["ANYWAY_ENV"]
|
101
|
-
|
102
|
-
# By default, use local files only in development (that's the purpose if the local files)
|
103
|
-
self.use_local_files = (ENV["ANYWAY_ENV"] == "development" || ENV["RACK_ENV"] == "development" || ENV["RAILS_ENV"] == "development" || (defined?(Rails) && Rails.env.development?))
|
104
|
-
|
105
|
-
# By default, consider configs are stored in the ./config folder
|
106
|
-
self.default_config_path = ->(name) { "./config/#{name}.yml" }
|
107
|
-
|
108
|
-
# Tracing is enabled by default
|
109
|
-
self.tracing_enabled = true
|
110
|
-
end
|
111
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Anyway
|
4
|
-
module Testing
|
5
|
-
module Helpers
|
6
|
-
# Sets the ENV variables to the provided
|
7
|
-
# values and restore outside the block
|
8
|
-
#
|
9
|
-
# Also resets Anyway.env before and after calling the block
|
10
|
-
# to make sure that the values are not cached.
|
11
|
-
#
|
12
|
-
# NOTE: to remove the env value, pass `nil` as the value
|
13
|
-
def with_env(data)
|
14
|
-
was_values = []
|
15
|
-
|
16
|
-
data.each do |key, val|
|
17
|
-
was_values << [key, ENV[key]]
|
18
|
-
next ENV.delete(key) if val.nil?
|
19
|
-
ENV[key] = val
|
20
|
-
end
|
21
|
-
|
22
|
-
# clear cached env values
|
23
|
-
Anyway.env.clear
|
24
|
-
yield
|
25
|
-
ensure
|
26
|
-
was_values.each do |(key, val)|
|
27
|
-
next ENV.delete(key) if val.nil?
|
28
|
-
ENV[key] = val
|
29
|
-
end
|
30
|
-
|
31
|
-
# clear cache again
|
32
|
-
Anyway.env.clear
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/anyway/tracing.rb
DELETED
@@ -1,188 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Anyway
|
4
|
-
# Provides method to trace values association
|
5
|
-
module Tracing
|
6
|
-
using Anyway::Ext::DeepDup
|
7
|
-
|
8
|
-
using(Module.new do
|
9
|
-
refine Thread::Backtrace::Location do
|
10
|
-
def path_lineno = "#{path}:#{lineno}"
|
11
|
-
end
|
12
|
-
end)
|
13
|
-
|
14
|
-
class Trace
|
15
|
-
UNDEF = Object.new
|
16
|
-
|
17
|
-
attr_reader :type, :value, :source
|
18
|
-
|
19
|
-
def initialize(type = :trace, value = UNDEF, **source)
|
20
|
-
@type = type
|
21
|
-
@source = source
|
22
|
-
@value = (value == UNDEF) ? Hash.new { |h, k| h[k] = Trace.new(:trace) } : value
|
23
|
-
end
|
24
|
-
|
25
|
-
def dig(...)
|
26
|
-
value.dig(...)
|
27
|
-
end
|
28
|
-
|
29
|
-
def record_value(val, *path, **)
|
30
|
-
key = path.pop
|
31
|
-
trace = if val.is_a?(Hash)
|
32
|
-
Trace.new.tap { _1.merge_values(val, **) }
|
33
|
-
else
|
34
|
-
Trace.new(:value, val, **)
|
35
|
-
end
|
36
|
-
|
37
|
-
target_trace = path.empty? ? self : value.dig(*path)
|
38
|
-
target_trace.record_key(key.to_s, trace)
|
39
|
-
|
40
|
-
val
|
41
|
-
end
|
42
|
-
|
43
|
-
def merge_values(hash, **)
|
44
|
-
return hash unless hash
|
45
|
-
|
46
|
-
hash.each do |key, val|
|
47
|
-
if val.is_a?(Hash)
|
48
|
-
value[key.to_s].merge_values(val, **)
|
49
|
-
else
|
50
|
-
value[key.to_s] = Trace.new(:value, val, **)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
hash
|
55
|
-
end
|
56
|
-
|
57
|
-
def record_key(key, key_trace)
|
58
|
-
@value = Hash.new { |h, k| h[k] = Trace.new(:trace) } unless value.is_a?(::Hash)
|
59
|
-
|
60
|
-
value[key] = key_trace
|
61
|
-
end
|
62
|
-
|
63
|
-
def merge!(another_trace)
|
64
|
-
raise ArgumentError, "You can only merge into a :trace type, and this is :#{type}" unless trace?
|
65
|
-
raise ArgumentError, "You can only merge a :trace type, but trying :#{type}" unless another_trace.trace?
|
66
|
-
|
67
|
-
another_trace.value.each do |key, sub_trace|
|
68
|
-
if sub_trace.trace?
|
69
|
-
value[key].merge! sub_trace
|
70
|
-
else
|
71
|
-
value[key] = sub_trace
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def keep_if(...)
|
77
|
-
raise ArgumentError, "You can only filter :trace type, and this is :#{type}" unless trace?
|
78
|
-
value.keep_if(...)
|
79
|
-
end
|
80
|
-
|
81
|
-
def clear = value.clear
|
82
|
-
|
83
|
-
def trace? = type == :trace
|
84
|
-
|
85
|
-
def to_h
|
86
|
-
if trace?
|
87
|
-
value.transform_values(&:to_h).tap { _1.default_proc = nil }
|
88
|
-
else
|
89
|
-
{value:, source:}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def dup = self.class.new(type, value.dup, **source)
|
94
|
-
|
95
|
-
def pretty_print(q)
|
96
|
-
if trace?
|
97
|
-
q.nest(2) do
|
98
|
-
q.breakable ""
|
99
|
-
q.seplist(value, nil, :each) do |k, v|
|
100
|
-
q.group do
|
101
|
-
q.text k
|
102
|
-
q.text " =>"
|
103
|
-
if v.trace?
|
104
|
-
q.text " { "
|
105
|
-
q.pp v
|
106
|
-
q.breakable " "
|
107
|
-
q.text "}"
|
108
|
-
else
|
109
|
-
q.breakable " "
|
110
|
-
q.pp v
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
else
|
116
|
-
q.pp value
|
117
|
-
q.group(0, " (", ")") do
|
118
|
-
q.seplist(source, lambda { q.breakable " " }, :each) do |k, v|
|
119
|
-
q.group do
|
120
|
-
q.text k.to_s
|
121
|
-
q.text "="
|
122
|
-
q.text v.to_s
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
class << self
|
131
|
-
def capture
|
132
|
-
unless Settings.tracing_enabled
|
133
|
-
yield
|
134
|
-
return
|
135
|
-
end
|
136
|
-
|
137
|
-
trace = Trace.new
|
138
|
-
trace_stack.push trace
|
139
|
-
yield
|
140
|
-
trace_stack.last
|
141
|
-
ensure
|
142
|
-
trace_stack.pop
|
143
|
-
end
|
144
|
-
|
145
|
-
def trace_stack
|
146
|
-
(Thread.current[:__anyway__trace_stack__] ||= [])
|
147
|
-
end
|
148
|
-
|
149
|
-
def current_trace = trace_stack.last
|
150
|
-
|
151
|
-
alias_method :tracing?, :current_trace
|
152
|
-
|
153
|
-
def source_stack
|
154
|
-
(Thread.current[:__anyway__trace_source_stack__] ||= [])
|
155
|
-
end
|
156
|
-
|
157
|
-
def current_trace_source
|
158
|
-
source_stack.last || accessor_source(caller_locations(2, 1).first)
|
159
|
-
end
|
160
|
-
|
161
|
-
def with_trace_source(src)
|
162
|
-
source_stack << src
|
163
|
-
yield
|
164
|
-
ensure
|
165
|
-
source_stack.pop
|
166
|
-
end
|
167
|
-
|
168
|
-
private
|
169
|
-
|
170
|
-
def accessor_source(location)
|
171
|
-
{type: :accessor, called_from: location.path_lineno}
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
module_function
|
176
|
-
|
177
|
-
def trace!(type, *path, **)
|
178
|
-
return yield unless Tracing.tracing?
|
179
|
-
val = yield
|
180
|
-
if val.is_a?(Hash)
|
181
|
-
Tracing.current_trace.merge_values(val, type:, **)
|
182
|
-
elsif !path.empty?
|
183
|
-
Tracing.current_trace.record_value(val, *path, type:, **)
|
184
|
-
end
|
185
|
-
val
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
data/lib/anyway/utils/which.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Anyway
|
4
|
-
module Utils
|
5
|
-
# Cross-platform solution
|
6
|
-
# taken from https://stackoverflow.com/a/5471032
|
7
|
-
def self.which(cmd)
|
8
|
-
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
|
9
|
-
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
10
|
-
exts.each do |ext|
|
11
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
12
|
-
return exe if File.executable?(exe) && !File.directory?(exe)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/anyway/version.rb
DELETED
data/lib/anyway_config.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "anyway/version"
|
4
|
-
|
5
|
-
require "anyway/ext/deep_dup"
|
6
|
-
require "anyway/ext/deep_freeze"
|
7
|
-
require "anyway/ext/hash"
|
8
|
-
require "anyway/ext/flatten_names"
|
9
|
-
|
10
|
-
require "anyway/utils/deep_merge"
|
11
|
-
require "anyway/utils/which"
|
12
|
-
|
13
|
-
require "anyway/settings"
|
14
|
-
require "anyway/tracing"
|
15
|
-
require "anyway/config"
|
16
|
-
require "anyway/auto_cast"
|
17
|
-
require "anyway/type_casting"
|
18
|
-
require "anyway/env"
|
19
|
-
require "anyway/loaders"
|
20
|
-
require "anyway/rbs"
|
21
|
-
|
22
|
-
module Anyway # :nodoc:
|
23
|
-
class << self
|
24
|
-
def env
|
25
|
-
@env ||= ::Anyway::Env.new
|
26
|
-
end
|
27
|
-
|
28
|
-
def loaders
|
29
|
-
@loaders ||= ::Anyway::Loaders::Registry.new
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Configure default loaders
|
34
|
-
loaders.append :yml, Loaders::YAML
|
35
|
-
loaders.append :ejson, Loaders::EJSON if Utils.which("ejson")
|
36
|
-
loaders.append :env, Loaders::Env
|
37
|
-
|
38
|
-
if ENV.key?("DOPPLER_TOKEN") && ENV["ANYWAY_CONFIG_DISABLE_DOPPLER"] != "true"
|
39
|
-
loaders.append :doppler, Loaders::Doppler
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
if defined?(::Rails::VERSION)
|
44
|
-
require "anyway/rails"
|
45
|
-
else
|
46
|
-
require "anyway/rails/autoload"
|
47
|
-
end
|
48
|
-
|
49
|
-
require "anyway/testing" if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test"
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "generators/anyway/config/config_generator"
|
4
|
-
|
5
|
-
module Anyway
|
6
|
-
module Generators
|
7
|
-
class AppConfigGenerator < ConfigGenerator
|
8
|
-
source_root ConfigGenerator.source_root
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def config_root
|
13
|
-
"app/configs"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails/generators"
|
4
|
-
|
5
|
-
module Anyway
|
6
|
-
module Generators
|
7
|
-
class 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
|
-
generate "anyway:install"
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_config
|
22
|
-
template "config.rb", File.join(config_root, class_path, "#{file_name}_config.rb")
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_yml
|
26
|
-
create_yml = options.fetch(:yml) { yes?("Would you like to generate a #{file_name}.yml file?") }
|
27
|
-
return unless create_yml
|
28
|
-
template "config.yml", File.join("config", "#{file_name}.yml")
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def static_config_root
|
34
|
-
Anyway::Settings.autoload_static_config_path || Anyway::DEFAULT_CONFIGS_PATH
|
35
|
-
end
|
36
|
-
|
37
|
-
def config_root
|
38
|
-
if options[:app]
|
39
|
-
"app/configs"
|
40
|
-
else
|
41
|
-
static_config_root
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails/generators"
|
4
|
-
|
5
|
-
module Anyway
|
6
|
-
module Generators
|
7
|
-
class 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
|
-
# Configure the path for configuration classes that should be used before initialization
|
28
|
-
# NOTE: path should be relative to the project root (Rails.root)
|
29
|
-
#{maybe_comment_indented}config.anyway_config.autoload_static_config_path = "#{static_config_root}"
|
30
|
-
#{maybe_comment_indented.sub(/\s+$/, "")}
|
31
|
-
RUBY
|
32
|
-
end
|
33
|
-
end
|
34
|
-
# rubocop:enable Layout/HeredocIndentation
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def static_config_root
|
39
|
-
options[:configs_path] || Anyway::Settings.autoload_static_config_path || Anyway::DEFAULT_CONFIGS_PATH
|
40
|
-
end
|
41
|
-
|
42
|
-
def default_configs_path?
|
43
|
-
static_config_root == (Anyway::Settings.autoload_static_config_path || Anyway::DEFAULT_CONFIGS_PATH)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|