class Alerty::Config

Attributes

opts[R]

Public Class Methods

config() click to toggle source
# File lib/alerty/config.rb, line 18
def config
  return @config if @config
  if dotenv?
    require 'dotenv'
    Dotenv.load
  end
  content = File.read(config_path)
  erb = ERB.new(content, nil, '-')
  erb_content = erb.result
  if debug?
    puts '=== Erb evaluated config ==='
    puts erb_content
  end
  yaml = YAML.load(erb_content)
  @config = Hashie::Mash.new(yaml)
  if debug?
    puts '=== Recognized config ==='
    puts({
      'log_path' => log_path,
      'log_level' => log_level,
      'log_shift_age' => log_shift_age,
      'log_shift_size' => log_shift_size,
      'timeout' => timeout,
      'lock_path' => lock_path,
      'retry_limit' => retry_limit,
      'retry_wait' => retry_wait,
      'plugins' => yaml['plugins'],
    }.to_yaml)
  end
  @config
end
config_path() click to toggle source
# File lib/alerty/config.rb, line 14
def config_path
  @config_path ||= opts[:config_path] || ENV['ALERTY_CONFIG_PATH'] || '/etc/alerty/alerty.yml'
end
configure(opts) click to toggle source
# File lib/alerty/config.rb, line 10
def configure(opts)
  @opts = opts
end
debug?() click to toggle source
# File lib/alerty/config.rb, line 84
def debug?
  !!opts[:debug]
end
dotenv?() click to toggle source
# File lib/alerty/config.rb, line 88
def dotenv?
  !!opts[:dotenv]
end
lock_path() click to toggle source
# File lib/alerty/config.rb, line 72
def lock_path
  opts[:lock_path] || config.lock_path
end
log_level() click to toggle source
# File lib/alerty/config.rb, line 54
def log_level
  opts[:log_level] || config.log_level || 'warn'
end
log_path() click to toggle source
# File lib/alerty/config.rb, line 50
def log_path
  opts[:log_path] || config.log_path || 'STDOUT'
end
log_shift_age() click to toggle source
# File lib/alerty/config.rb, line 58
def log_shift_age
  # config.shift_age is for old version compatibility
  opts[:log_shift_age] || config.shift_age || config.log_shift_age || 0
end
log_shift_size() click to toggle source
# File lib/alerty/config.rb, line 63
def log_shift_size
  # config.log_shift_age is for old version compatibility
  opts[:log_shift_size] || config.shift_size || config.log_shift_size || 1048576
end
plugins() click to toggle source
# File lib/alerty/config.rb, line 98
def plugins
  @plugins ||= config.fetch('plugins')
end
reset() click to toggle source

for debug

# File lib/alerty/config.rb, line 103
def reset
  @config_path = nil
  @config = nil
  @plugins = nil
end
retry_interval() click to toggle source
# File lib/alerty/config.rb, line 92
def retry_interval
  @random ||= Random.new
  randomness = retry_wait * 0.125
  retry_wait + @random.rand(-randomness .. randomness)
end
retry_limit() click to toggle source
# File lib/alerty/config.rb, line 76
def retry_limit
  opts[:retry_limit] || config.retry_limit || 0
end
retry_wait() click to toggle source
# File lib/alerty/config.rb, line 80
def retry_wait
  opts[:retry_wait] || config.retry_wait || 1.0
end
timeout() click to toggle source
# File lib/alerty/config.rb, line 68
def timeout
  opts[:timeout] || config.timeout
end