Module: Rimless::Extensions::ConfigurationHandling

Extended by:
ActiveSupport::Concern
Included in:
Rimless
Defined in:
lib/rimless/extensions/configuration_handling.rb

Overview

The top-level configuration handling.

rubocop:disable-next Style/ClassVars -- because we split module code

Class Method Summary collapse

Class Method Details

.configuration ⇒ Configuration

Retrieve the current configuration object.

Returns:



15
16
17
# File 'lib/rimless/extensions/configuration_handling.rb', line 15

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

Yields:



25
26
27
28
# File 'lib/rimless/extensions/configuration_handling.rb', line 25

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?.

Returns:

  • (ActiveSupport::StringInquirer) —

    the environment



39
40
41
42
43
# File 'lib/rimless/extensions/configuration_handling.rb', line 39

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.

Returns:

  • (String, nil) —

    the Rails application name, or nil



59
60
61
62
63
64
65
66
67
# File 'lib/rimless/extensions/configuration_handling.rb', line 59

def local_app_name
  # Check for non-Rails integration
  return unless defined? Rails
  # Check if a application is defined
  return if Rails.application.nil?

  # Pass back the URI compatible application name
  Rails.application.class.module_parent_name.underscore.dasherize
end

.logger ⇒ Logger

Retrieve the current configured logger instance.

Returns:

  • (Logger) —

    the logger instance



72
# File 'lib/rimless/extensions/configuration_handling.rb', line 72

delegate :logger, to: :configuration

.reset_configuration! ⇒ Object

Reset the current configuration with the default one.



31
32
33
# File 'lib/rimless/extensions/configuration_handling.rb', line 31

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.

Parameters:

  • app (String) (defaults to: Rimless.configuration.app_name) —

    the application namespace

Returns:

  • (String) —

    the Apache Kafka topic name prefix



49
50
51
# File 'lib/rimless/extensions/configuration_handling.rb', line 49

def topic_prefix(app = Rimless.configuration.app_name)
  "#{Rimless.env}.#{app}."
end