Sha256: 0e0b96f90c4e513fe35aa1ac2b3b45b3b68458660e5675ff75602ddf87f0728d

Contents?: true

Size: 999 Bytes

Versions: 2

Compression:

Stored size: 999 Bytes

Contents

require 'yaml'
require 'pause'
require 'spanx/helper/exit'
require 'spanx/ip_checker'

module Spanx
  class Config < Hash
    include Spanx::Helper::Exit

    attr_accessor :filename

    def initialize(filename)
      super
      @filename = filename
      load_file

      Pause.configure do |pause|
        pause.redis_host = self[:redis][:host]
        pause.redis_port = self[:redis][:port]
        pause.redis_db = self[:redis][:database]

        pause.resolution = self[:collector][:resolution]
        pause.history = self[:collector][:history]
      end

      if self.has_key?(:analyzer) && self[:analyzer].has_key?(:period_checks)
        self[:analyzer][:period_checks].each do |check|
          Spanx::IPChecker.check(check)
        end
      end

      self
    end

    private

    def load_file
      begin
        self.merge! ::YAML.load_file(filename)
      rescue Errno::ENOENT
        error_exit_with_msg "Unable to find config_file at #{filename}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spanx-0.3.0 lib/spanx/config.rb
spanx-0.1.1 lib/spanx/config.rb