Module: Rimless::ConfigurationHandling
- Extended by:
- ActiveSupport::Concern
- Included in:
- Rimless
- Defined in:
- lib/rimless/configuration_handling.rb
Overview
The top-level configuration handling.
rubocop:disable Style/ClassVars because we split module code rubocop:disable Metrics/BlockLength because this is how
an +ActiveSupport::Concern+ looks like
Class Method Summary collapse
-
.configuration ⇒ Configuration
Retrieve the current configuration object.
-
.configure {|configuration| ... } ⇒ Object
Configure the concern by providing a block which takes care of this task.
-
.env ⇒ ActiveSupport::StringInquirer
Retrieve the current configured environment.
-
.local_app_name ⇒ String?
Pass back the local application name.
-
.logger ⇒ Logger
Retrieve the current configured logger instance.
-
.reset_configuration! ⇒ Object
Reset the current configuration with the default one.
-
.topic_prefix(app = Rimless.configuration.app_name) ⇒ String
A simple convention helper to setup Apache Kafka topic names.
Class Method Details
.configuration ⇒ Configuration
Retrieve the current configuration object.
16 17 18 |
# File 'lib/rimless/configuration_handling.rb', line 16 def configuration @@configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Configure the concern by providing a block which takes care of this task. Example:
FactoryBot::Instrumentation.configure do |conf|
# conf.xyz = [..]
end
26 27 28 29 |
# File 'lib/rimless/configuration_handling.rb', line 26 def configure yield(configuration) configure_dependencies end |
.env ⇒ ActiveSupport::StringInquirer
Retrieve the current configured environment. You can use it like Rails.env
to query it. E.g. Rimless.env.production?
.
40 41 42 43 44 |
# File 'lib/rimless/configuration_handling.rb', line 40 def env @@env = ActiveSupport::StringInquirer.new(configuration.env.to_s) \ if @env.to_s != configuration.env.to_s @@env end |
.local_app_name ⇒ String?
Pass back the local application name. When we are loaded together with a Rails application we use the application class name. This application name is URI/GID compatible. When no local application is available, we just pass back nil
.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rimless/configuration_handling.rb', line 60 def local_app_name # Check for non-Rails integration return unless defined? Rails # Check if a application is defined return if Rails.application.nil? # We need a little compatibility here, as in Rails 6.1+ there is no # more +parent_name+, instead they renamed it to +module_parent_name+ app_class = Rails.application.class parent_name = app_class.module_parent_name \ if app_class.respond_to?(:module_parent_name) parent_name ||= app_class.parent_name # Pass back the URI compatible application name parent_name.underscore.dasherize end |
.logger ⇒ Logger
Retrieve the current configured logger instance.
80 |
# File 'lib/rimless/configuration_handling.rb', line 80 delegate :logger, to: :configuration |
.reset_configuration! ⇒ Object
Reset the current configuration with the default one.
32 33 34 |
# File 'lib/rimless/configuration_handling.rb', line 32 def reset_configuration! @@configuration = Configuration.new end |
.topic_prefix(app = Rimless.configuration.app_name) ⇒ String
A simple convention helper to setup Apache Kafka topic names.
50 51 52 |
# File 'lib/rimless/configuration_handling.rb', line 50 def topic_prefix(app = Rimless.configuration.app_name) "#{Rimless.env}.#{app}." end |