Class: Rimless::Configuration

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/rimless/configuration.rb

Overview

The configuration for the rimless gem.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Configuration

Create a new Configuration instance with all settings populated with their respective defaults.

Parameters:

  • args (Hash{Symbol => Mixed})

    additional settings which overwrite the defaults



20
21
22
23
24
# File 'lib/rimless/configuration.rb', line 20

def initialize(**args)
  super()
  defaults.each { |key, default| self[key] = instance_exec(&default) }
  merge!(**args)
end

Class Method Details

.config_accessor(name, default = nil, &block) ⇒ Object

A simple DSL method to define new configuration accessors/settings with their defaults. The defaults can be retrieved with Configuration.defaults or Configuration.new.defaults.

Parameters:

  • name (Symbol, String)

    the name of the configuration accessor/setting

  • default (Mixed, nil) (defaults to: nil)

    a non-lazy-loaded static value, serving as a default value for the setting

  • block (Proc)

    when given, the default value will be lazy-loaded (result of the Proc)



36
37
38
39
40
41
42
43
44
# File 'lib/rimless/configuration.rb', line 36

def self.config_accessor(name, default = nil, &block)
  # Save the given configuration accessor default value
  defaults[name.to_sym] = block || -> { default }

  # Compile reader/writer methods so we don't have to go through
  # +ActiveSupport::OrderedOptions#method_missing+.
  define_method(name) { self[name] }
  define_method("#{name}=") { |value| self[name] = value }
end

Instance Method Details

#consumer_job_queue=(val) ⇒ Object

A custom writer for the consumer job queue name.

Parameters:

  • val (String, Symbol)

    the new job queue name



153
154
155
156
157
158
# File 'lib/rimless/configuration.rb', line 153

def consumer_job_queue=(val)
  self[:consumer_job_queue] = val.to_sym

  # Refresh the consumer job queue
  consumer_job_class.queue_as(val)
end

#kafka_brokers=(val) ⇒ Object

A custom writer for the kafka brokers configuration.

Parameters:

  • val (String, Array<String>)

    the new kafka brokers list



81
82
83
84
85
86
# File 'lib/rimless/configuration.rb', line 81

def kafka_brokers=(val)
  self[:kafka_brokers] =
    Array(val).join(',').split(',')
              .map { |uri| uri.split('://', 2).last }
              .join(',')
end