runger_config 4.0.0 → 5.0.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/generators/runger/app_config/app_config_generator.rb +6 -10
  4. data/lib/generators/runger/config/config_generator.rb +44 -41
  5. data/lib/generators/runger/install/install_generator.rb +35 -37
  6. data/lib/runger/auto_cast.rb +3 -3
  7. data/lib/runger/config.rb +114 -94
  8. data/lib/runger/dynamic_config.rb +21 -23
  9. data/lib/runger/ejson_parser.rb +24 -24
  10. data/lib/runger/env.rb +50 -52
  11. data/lib/runger/ext/deep_dup.rb +33 -36
  12. data/lib/runger/ext/deep_freeze.rb +28 -32
  13. data/lib/runger/ext/flatten_names.rb +23 -27
  14. data/lib/runger/ext/hash.rb +26 -29
  15. data/lib/runger/ext/string_constantize.rb +12 -15
  16. data/lib/runger/loaders/base.rb +11 -15
  17. data/lib/runger/loaders/doppler.rb +38 -42
  18. data/lib/runger/loaders/ejson.rb +65 -63
  19. data/lib/runger/loaders/env.rb +6 -10
  20. data/lib/runger/loaders/yaml.rb +69 -66
  21. data/lib/runger/loaders.rb +69 -71
  22. data/lib/runger/option_parser_builder.rb +16 -18
  23. data/lib/runger/optparse_config.rb +11 -10
  24. data/lib/runger/rails/autoload.rb +24 -26
  25. data/lib/runger/rails/config.rb +13 -17
  26. data/lib/runger/rails/loaders/credentials.rb +53 -57
  27. data/lib/runger/rails/loaders/secrets.rb +21 -25
  28. data/lib/runger/rails/loaders/yaml.rb +1 -6
  29. data/lib/runger/rails/loaders.rb +3 -3
  30. data/lib/runger/rails/settings.rb +49 -49
  31. data/lib/runger/rails.rb +9 -11
  32. data/lib/runger/railtie.rb +3 -2
  33. data/lib/runger/rbs.rb +29 -29
  34. data/lib/runger/settings.rb +82 -84
  35. data/lib/runger/testing/helpers.rb +26 -28
  36. data/lib/runger/testing.rb +2 -2
  37. data/lib/runger/tracing.rb +143 -136
  38. data/lib/runger/type_casting.rb +16 -11
  39. data/lib/runger/utils/which.rb +10 -12
  40. data/lib/runger/version.rb +1 -1
  41. data/lib/runger.rb +1 -1
  42. data/lib/runger_config.rb +34 -27
  43. metadata +18 -18
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "runger/option_parser_builder"
3
+ require 'runger/option_parser_builder'
4
4
 
5
- require "runger/ext/deep_dup"
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 === desc
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 ||= OptionParserBuilder.call(self.class.option_parser_options) do |key, val|
74
- write_config_attr(key, val)
75
- end.tap do |parser|
76
- self.class.option_parser_extensions.map do |extension|
77
- extension.call(parser, self)
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 ClassMethods
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
- module Rails
7
- class << self
8
- attr_reader :tracer, :name_method
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
- private
10
+ private
12
11
 
13
- def tracepoint_class_callback(event)
14
- # Ignore singletons
15
- return if event.self.singleton_class?
12
+ def tracepoint_class_callback(event)
13
+ # Ignore singletons
14
+ return if event.self.singleton_class?
16
15
 
17
- # We wait till `rails/application/configuration.rb` has been loaded, since we rely on it
18
- # See https://github.com/palkan/runger_config/issues/134
19
- return unless name_method.bind_call(event.self) == "Rails::Application::Configuration"
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
- tracer.disable
20
+ tracer.disable
22
21
 
23
- unless disable_postponed_load_warning
24
- warn "Runger Config was loaded before Rails. Activating Runger Config Rails plugins now.\n" \
25
- "NOTE: Already loaded configs were provisioned without Rails-specific sources."
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
- # TruffleRuby doesn't support TracePoint's end event
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
@@ -1,23 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/hash/indifferent_access"
3
+ require 'active_support/core_ext/hash/indifferent_access'
4
4
 
5
- module Runger
6
- module Rails
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 Config
12
- module ClassMethods
13
- # Make defaults to be a Hash with indifferent access
14
- def new_empty_config
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 Runger::Rails::Config
23
- Runger::Config.singleton_class.prepend Runger::Rails::Config::ClassMethods
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
- module Rails
5
- module Loaders
6
- class Credentials < Runger::Loaders::Base
7
- LOCAL_CONTENT_PATH = "config/credentials/local.yml.enc"
8
-
9
- def call(name:, **_options)
10
- return {} unless ::Rails.application.respond_to?(:credentials)
11
-
12
- # do not load from credentials if we're in the context
13
- # of the `credentials:edit` command
14
- return {} if defined?(::Rails::Command::CredentialsCommand)
15
-
16
- # Create a new hash cause credentials are mutable!
17
- config = {}
18
-
19
- trace!(
20
- :credentials,
21
- store: credentials_path
22
- ) do
23
- ::Rails.application.credentials.config[name.to_sym]
24
- end.then do |creds|
25
- Utils.deep_merge!(config, creds) if creds
26
- end
27
-
28
- if use_local?
29
- trace!(:credentials, store: LOCAL_CONTENT_PATH) do
30
- local_credentials(name)
31
- end.then { |creds| Utils.deep_merge!(config, creds) if creds }
32
- end
33
-
34
- config
35
- end
36
-
37
- private
38
-
39
- def local_credentials(name)
40
- local_creds_path = ::Rails.root.join(LOCAL_CONTENT_PATH).to_s
41
-
42
- return unless File.file?(local_creds_path)
43
-
44
- creds = ::Rails.application.encrypted(
45
- local_creds_path,
46
- key_path: ::Rails.root.join("config/credentials/local.key")
47
- )
48
-
49
- creds.config[name.to_sym]
50
- end
51
-
52
- def credentials_path
53
- if ::Rails.application.config.respond_to?(:credentials)
54
- ::Rails.root.join(::Rails.application.config.credentials.content_path).relative_path_from(::Rails.root).to_s
55
- else
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
- module Runger
4
- module Rails
5
- module Loaders
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
- # Create a new hash cause secrets are mutable!
11
- config = {}
7
+ # Create a new hash cause secrets are mutable!
8
+ config = {}
12
9
 
13
- trace!(:secrets) do
14
- secrets.public_send(name)
15
- end.then do |secrets|
16
- Utils.deep_merge!(config, secrets) if secrets
17
- end
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
- config
20
- end
19
+ private
21
20
 
22
- private
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
- def secrets
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
@@ -1,9 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Runger
4
- module Rails
5
- module Loaders
6
- class YAML < Runger::Loaders::YAML; end
7
- end
8
- end
3
+ class Runger::Rails::Loaders::YAML < Runger::Loaders::YAML
9
4
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "runger/rails/loaders/yaml"
4
- require "runger/rails/loaders/secrets"
5
- require "runger/rails/loaders/credentials"
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 "zeitwerk"
6
- require "active_support/dependencies/zeitwerk_integration"
5
+ require 'active_support/dependencies/zeitwerk_integration'
6
+ require 'zeitwerk'
7
7
  rescue LoadError
8
8
  end
9
9
 
10
- module Runger
11
- class Settings
12
- class << self
13
- attr_reader :autoload_static_config_path, :autoloader
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
- 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?
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
- return unless ::Rails.root.join(val).exist?
19
+ return unless ::Rails.root.join(val).exist?
21
20
 
22
- return if val == autoload_static_config_path
21
+ return if val == autoload_static_config_path
23
22
 
24
- autoloader&.unload
23
+ autoloader&.unload
25
24
 
26
- @autoload_static_config_path = val
25
+ @autoload_static_config_path = val
27
26
 
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 = "runger.config"
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
- 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
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
- def cleanup_autoload_paths
56
- return unless autoload_via_zeitwerk
55
+ def cleanup_autoload_paths
56
+ return unless autoload_via_zeitwerk
57
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
58
+ return unless autoload_static_config_path
61
59
 
62
- def autoload_via_zeitwerk
63
- return @autoload_via_zeitwerk if instance_variable_defined?(:@autoload_via_zeitwerk)
60
+ ActiveSupport::Dependencies.autoload_paths.delete(::Rails.root.join(autoload_static_config_path).to_s)
61
+ end
64
62
 
65
- @autoload_via_zeitwerk = defined?(::Zeitwerk)
66
- end
63
+ def autoload_via_zeitwerk
64
+ return @autoload_via_zeitwerk if instance_variable_defined?(:@autoload_via_zeitwerk)
67
65
 
68
- def current_environment
69
- @current_environment || ::Rails.env.to_s
70
- end
66
+ @autoload_via_zeitwerk = defined?(::Zeitwerk)
67
+ end
71
68
 
72
- def app_root
73
- ::Rails.root
74
- end
69
+ def current_environment
70
+ @current_environment || ::Rails.env.to_s
75
71
  end
76
72
 
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
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 "runger/rails/settings"
9
- require "runger/rails/config"
10
- require "runger/rails/loaders"
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 :yml, Runger::Rails::Loaders::YAML
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 :yml, :credentials, Runger::Rails::Loaders::Credentials
14
+ Runger.loaders.insert_after(:yml, :credentials, Runger::Rails::Loaders::Credentials)
17
15
  else
18
- Runger.loaders.insert_after :yml, :secrets, Runger::Rails::Loaders::Secrets
19
- Runger.loaders.insert_after :secrets, :credentials, Runger::Rails::Loaders::Credentials
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 "runger/railtie"
22
+ require 'runger/railtie'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Runger # :nodoc:
4
- DEFAULT_CONFIGS_PATH = "config/configs"
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 "runger_config.cleanup_autoload" do
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: "String",
7
- integer: "Integer",
8
- float: "Float",
9
- date: "Date",
10
- datetime: "DateTime",
11
- uri: "URI",
12
- boolean: "bool"
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 = "_Config"
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 << "#{" " * indent}interface #{interface_name}"
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
- "untyped"
42
+ 'untyped'
43
43
  in Symbol
44
- TYPE_TO_CLASS.fetch(type) { defaults[param] ? "Symbol" : "untyped" }
44
+ TYPE_TO_CLASS.fetch(type) { defaults[param] ? 'Symbol' : 'untyped' }
45
45
  in Array
46
- "Array[untyped]"
46
+ 'Array[untyped]'
47
47
  in array: _, type:, **nil
48
- "Array[#{TYPE_TO_CLASS.fetch(type, "untyped")}]"
48
+ "Array[#{TYPE_TO_CLASS.fetch(type, 'untyped')}]"
49
49
  in Hash
50
- "Hash[string,untyped]"
50
+ 'Hash[string,untyped]'
51
51
  in TrueClass | FalseClass
52
- "bool"
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 << "#{" " * indent}def #{param}: () -> #{getter_type}"
61
- buf << "#{" " * indent}def #{param}=: (#{type}) -> void"
60
+ buf << "#{' ' * indent}def #{param}: () -> #{getter_type}"
61
+ buf << "#{' ' * indent}def #{param}=: (#{type}) -> void"
62
62
 
63
- if type == "bool" || type == "bool?"
64
- buf << "#{" " * indent}def #{param}?: () -> #{getter_type}"
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 << "#{" " * indent}end"
69
+ buf << "#{' ' * indent}end"
70
70
 
71
- buf << ""
71
+ buf << ''
72
72
 
73
- buf << "#{" " * indent}class #{class_name} < #{superclass.name}"
73
+ buf << "#{' ' * indent}class #{class_name} < #{superclass.name}"
74
74
  indent += 1
75
75
 
76
- buf << "#{" " * indent}include #{interface_name}"
76
+ buf << "#{' ' * indent}include #{interface_name}"
77
77
 
78
78
  indent -= 1
79
- buf << "#{" " * indent}end"
79
+ buf << "#{' ' * indent}end"
80
80
 
81
81
  unless namespace.empty?
82
- buf << "end"
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 RBSGenerator
91
+ Config.extend(RBSGenerator)
92
92
  end