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



107
108
109
110
111
112
113
# File 'lib/rimless/configuration.rb', line 107

def consumer_job_queue=(val)
  self[:consumer_job_queue] = val.to_sym
  # Refresh the consumer job queue
  Rimless::ConsumerJob.sidekiq_options(
    queue: Rimless.configuration.consumer_job_queue
  )
end