Class: Alerty::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/alerty/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optsObject (readonly)

Returns the value of attribute opts.



7
8
9
# File 'lib/alerty/config.rb', line 7

def opts
  @opts
end

Class Method Details

.configObject



17
18
19
# File 'lib/alerty/config.rb', line 17

def config
  @config ||= Hashie::Mash.new(YAML.load_file(config_path))
end

.config_pathObject



13
14
15
# File 'lib/alerty/config.rb', line 13

def config_path
  @config_path ||= opts[:config_path] || ENV['ALERTY_CONFIG_PATH'] || '/etc/alerty/alerty.yml'
end

.configure(opts) ⇒ Object



9
10
11
# File 'lib/alerty/config.rb', line 9

def configure(opts)
  @opts = opts
end

.lock_pathObject



41
42
43
# File 'lib/alerty/config.rb', line 41

def lock_path
  opts[:lock_path] || config.lock_path
end

.log_levelObject



25
26
27
# File 'lib/alerty/config.rb', line 25

def log_level
  opts[:log_level] || config.log_level || 'warn'
end

.log_pathObject



21
22
23
# File 'lib/alerty/config.rb', line 21

def log_path
  opts[:log_path] || config.log_path || 'STDOUT'
end

.log_shift_ageObject



29
30
31
# File 'lib/alerty/config.rb', line 29

def log_shift_age
  opts[:log_shift_age] || config.shift_age || 0
end

.log_shift_sizeObject



33
34
35
# File 'lib/alerty/config.rb', line 33

def log_shift_size
  opts[:log_shift_size] || config.shift_size || 1048576
end

.pluginsObject



59
60
61
62
63
64
65
# File 'lib/alerty/config.rb', line 59

def plugins
  @plugins ||= config.fetch('plugins').map do |plugin|
    require "alerty/plugin/#{plugin.type}"
    class_name = "Alerty::Plugin::#{StringUtil.camelize(plugin.type)}" 
    Object.const_get(class_name).new(plugin)
  end
end

.resetObject

for debug



68
69
70
71
72
# File 'lib/alerty/config.rb', line 68

def reset
  @config_path = nil
  @config = nil
  @plugins = nil
end

.retry_intervalObject



53
54
55
56
57
# File 'lib/alerty/config.rb', line 53

def retry_interval
  @random ||= Random.new
  randomness = retry_wait * 0.125
  retry_wait + @random.rand(-randomness .. randomness)
end

.retry_limitObject



45
46
47
# File 'lib/alerty/config.rb', line 45

def retry_limit
  opts[:retry_limit] || config.retry_limit || 0
end

.retry_waitObject



49
50
51
# File 'lib/alerty/config.rb', line 49

def retry_wait
  opts[:retry_wait] || config.retry_wait || 1.0
end

.timeoutObject



37
38
39
# File 'lib/alerty/config.rb', line 37

def timeout
  opts[:timeout] || config.timeout
end