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

Class Method Summary collapse

Class Method Details

.configurationConfiguration

Retrieve the current configuration object.

Returns:



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

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:



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

def configure
  yield(configuration)
  configure_dependencies
end

.envActiveSupport::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



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

def env
  @@env = ActiveSupport::StringInquirer.new(configuration.env.to_s) \
    if @env.to_s != configuration.env.to_s
  @@env
end

.local_app_nameString?

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



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

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.parent_name.underscore.dasherize
end

.loggerLogger

Retrieve the current configured logger instance.

Returns:

  • (Logger)

    the logger instance



71
# File 'lib/rimless/configuration_handling.rb', line 71

delegate :logger, to: :configuration

.reset_configuration!Object

Reset the current configuration with the default one.



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

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



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

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