Module: Salus::Configuration

Included in:
Salus
Defined in:
lib/salus/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring Salus.

%i(min_threads max_threads interval tick_timeout render_timeout logger).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Sets all configuration options to their default values when this module is extended.



11
12
13
# File 'lib/salus/configuration.rb', line 11

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block.

Yields:

  • (_self)

Yield Parameters:



16
17
18
# File 'lib/salus/configuration.rb', line 16

def configure
  yield self
end

#optionsObject

Creates a hash of options and their values.



21
22
23
24
25
# File 'lib/salus/configuration.rb', line 21

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Resets all configuration options to the defaults.



28
29
30
31
32
33
34
35
36
# File 'lib/salus/configuration.rb', line 28

def reset
  self.min_threads = CPU.count / 2
  self.min_threads = 1 if self.min_threads == 0
  self.max_threads = CPU.count * 2
  self.interval = 30
  self.tick_timeout   = 15
  self.render_timeout = 10
  self.logger   = Logger.new(STDERR)
end