Sha256: 06f5494aaa0c344d8445cbfe54876f71a390b57239105dc6c15bf79f50ab225e

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Salus
  module Configuration
    # An array of valid keys in the options hash when configuring Salus.
    VALID_OPTIONS_KEYS = %i(min_threads max_threads interval tick_timeout render_timeout logger).freeze

    # @private
    attr_accessor(*VALID_OPTIONS_KEYS)

    # Sets all configuration options to their default values
    # when this module is extended.
    def self.extended(base)
      base.reset
    end

    # Convenience method to allow configuration options to be set in a block.
    def configure
      yield self
    end

    # Creates a hash of options and their values.
    def options
      VALID_OPTIONS_KEYS.inject({}) do |option, key|
        option.merge!(key => send(key))
      end
    end

    # Resets all configuration options to the defaults.
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
salus-0.2.1 lib/salus/configuration.rb
salus-0.2.0 lib/salus/configuration.rb
salus-0.1.3 lib/salus/configuration.rb
salus-0.1.2 lib/salus/configuration.rb