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
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'runger/option_parser_builder'
|
4
4
|
|
5
|
-
require
|
5
|
+
require 'runger/ext/deep_dup'
|
6
6
|
|
7
7
|
module Runger
|
8
8
|
using Runger::Ext::DeepDup
|
@@ -19,7 +19,7 @@ module Runger
|
|
19
19
|
|
20
20
|
def describe_options(**hargs)
|
21
21
|
hargs.each do |name, desc|
|
22
|
-
if String
|
22
|
+
if desc.is_a?(String)
|
23
23
|
option_parser_descriptors[name.to_s][:desc] = desc
|
24
24
|
else
|
25
25
|
option_parser_descriptors[name.to_s].merge!(desc)
|
@@ -70,13 +70,14 @@ module Runger
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def option_parser
|
73
|
-
@option_parser ||=
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
@option_parser ||=
|
74
|
+
OptionParserBuilder.call(self.class.option_parser_options) do |key, val|
|
75
|
+
write_config_attr(key, val)
|
76
|
+
end.tap do |parser|
|
77
|
+
self.class.option_parser_extensions.map do |extension|
|
78
|
+
extension.call(parser, self)
|
79
|
+
end
|
78
80
|
end
|
79
|
-
end
|
80
81
|
end
|
81
82
|
|
82
83
|
def parse_options!(options)
|
@@ -86,7 +87,7 @@ module Runger
|
|
86
87
|
end
|
87
88
|
|
88
89
|
def self.included(base)
|
89
|
-
base.extend
|
90
|
+
base.extend(ClassMethods)
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -2,39 +2,37 @@
|
|
2
2
|
|
3
3
|
# This module is used to detect a Rails application and activate the corresponding plugins
|
4
4
|
# when Runger Config is loaded before Rails (e.g., in config/puma.rb).
|
5
|
-
module Runger
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
attr_accessor :disable_postponed_load_warning
|
5
|
+
module Runger::Rails
|
6
|
+
class << self
|
7
|
+
attr_reader :tracer, :name_method
|
8
|
+
attr_accessor :disable_postponed_load_warning
|
10
9
|
|
11
|
-
|
10
|
+
private
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def tracepoint_class_callback(event)
|
13
|
+
# Ignore singletons
|
14
|
+
return if event.self.singleton_class?
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
# We wait till `rails/application/configuration.rb` has been loaded, since we rely on it
|
17
|
+
# See https://github.com/palkan/runger_config/issues/134
|
18
|
+
return unless name_method.bind_call(event.self) == 'Rails::Application::Configuration'
|
20
19
|
|
21
|
-
|
20
|
+
tracer.disable
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
require "runger/rails"
|
22
|
+
unless disable_postponed_load_warning
|
23
|
+
warn("Runger Config was loaded before Rails. Activating Runger Config Rails plugins now.\n" \
|
24
|
+
'NOTE: Already loaded configs were provisioned without Rails-specific sources.')
|
29
25
|
end
|
30
|
-
end
|
31
26
|
|
32
|
-
|
33
|
-
unless defined?(::TruffleRuby)
|
34
|
-
@tracer = TracePoint.new(:end, &method(:tracepoint_class_callback))
|
35
|
-
@tracer.enable
|
36
|
-
# Use `Module#name` instead of `self.name` to handle overwritten `name` method
|
37
|
-
@name_method = Module.instance_method(:name)
|
27
|
+
require 'runger/rails'
|
38
28
|
end
|
39
29
|
end
|
30
|
+
|
31
|
+
# TruffleRuby doesn't support TracePoint's end event
|
32
|
+
unless defined?(::TruffleRuby)
|
33
|
+
@tracer = TracePoint.new(:end, &method(:tracepoint_class_callback))
|
34
|
+
@tracer.enable
|
35
|
+
# Use `Module#name` instead of `self.name` to handle overwritten `name` method
|
36
|
+
@name_method = Module.instance_method(:name)
|
37
|
+
end
|
40
38
|
end
|
data/lib/runger/rails/config.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
4
4
|
|
5
|
-
module Runger
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
{}.with_indifferent_access
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
5
|
+
module Runger::Rails::Config ; end
|
6
|
+
|
7
|
+
# Enhance config to be more Railsy-like:
|
8
|
+
# – accept hashes with indeferent access
|
9
|
+
# - load data from secrets
|
10
|
+
# - recognize Rails env when loading from YML
|
11
|
+
module Runger::Rails::Config::ClassMethods
|
12
|
+
# Make defaults to be a Hash with indifferent access
|
13
|
+
def new_empty_config
|
14
|
+
{}.with_indifferent_access
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
22
|
-
Runger::Config.prepend
|
23
|
-
Runger::Config.singleton_class.prepend
|
18
|
+
Runger::Config.prepend(Runger::Rails::Config)
|
19
|
+
Runger::Config.singleton_class.prepend(Runger::Rails::Config::ClassMethods)
|
@@ -1,62 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Runger
|
4
|
-
|
5
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
"config/credentials.yml.enc"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
3
|
+
module Runger::Rails::Loaders ; end
|
4
|
+
|
5
|
+
class Runger::Rails::Loaders::Credentials < Runger::Loaders::Base
|
6
|
+
LOCAL_CONTENT_PATH = 'config/credentials/local.yml.enc'
|
7
|
+
|
8
|
+
def call(name:, **_options)
|
9
|
+
return {} unless ::Rails.application.respond_to?(:credentials)
|
10
|
+
|
11
|
+
# do not load from credentials if we're in the context
|
12
|
+
# of the `credentials:edit` command
|
13
|
+
return {} if defined?(::Rails::Command::CredentialsCommand)
|
14
|
+
|
15
|
+
# Create a new hash cause credentials are mutable!
|
16
|
+
config = {}
|
17
|
+
|
18
|
+
trace!(
|
19
|
+
:credentials,
|
20
|
+
store: credentials_path,
|
21
|
+
) do
|
22
|
+
::Rails.application.credentials.config[name.to_sym]
|
23
|
+
end.then do |creds|
|
24
|
+
Runger::Utils.deep_merge!(config, creds) if creds
|
25
|
+
end
|
26
|
+
|
27
|
+
if use_local?
|
28
|
+
trace!(:credentials, store: LOCAL_CONTENT_PATH) do
|
29
|
+
local_credentials(name)
|
30
|
+
end.then { |creds| Runger::Utils.deep_merge!(config, creds) if creds }
|
31
|
+
end
|
32
|
+
|
33
|
+
config
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def local_credentials(name)
|
39
|
+
local_creds_path = ::Rails.root.join(LOCAL_CONTENT_PATH).to_s
|
40
|
+
|
41
|
+
return unless File.file?(local_creds_path)
|
42
|
+
|
43
|
+
creds = ::Rails.application.encrypted(
|
44
|
+
local_creds_path,
|
45
|
+
key_path: ::Rails.root.join('config/credentials/local.key'),
|
46
|
+
)
|
47
|
+
|
48
|
+
creds.config[name.to_sym]
|
49
|
+
end
|
50
|
+
|
51
|
+
def credentials_path
|
52
|
+
if ::Rails.application.config.respond_to?(:credentials)
|
53
|
+
::Rails.root.join(::Rails.application.config.credentials.content_path).relative_path_from(::Rails.root).to_s
|
54
|
+
else
|
55
|
+
'config/credentials.yml.enc'
|
60
56
|
end
|
61
57
|
end
|
62
58
|
end
|
@@ -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
|