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.



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

def opts
  @opts
end

Class Method Details

.configObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/alerty/config.rb', line 18

def config
  @config ||=
    begin
      if dotenv?
        require 'dotenv'
        Dotenv.load
      end
      content = File.read(config_path)
      erb = ERB.new(content, nil, '-')
      erb_content = erb.result
      puts erb_content if debug?
      Hashie::Mash.new(YAML.load(erb_content))
    end
end

.config_pathObject



14
15
16
# 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) ⇒ Object



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

def configure(opts)
  @opts = opts
end

.debug?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/alerty/config.rb', line 65

def debug?
  !!opts[:debug]
end

.dotenv?Boolean

Returns:

  • (Boolean)


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

def dotenv?
  !!opts[:dotenv]
end

.lock_pathObject



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

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

.log_levelObject



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

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

.log_pathObject



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

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

.log_shift_ageObject



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

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

.log_shift_sizeObject



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

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

.pluginsObject



79
80
81
82
83
84
85
# File 'lib/alerty/config.rb', line 79

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



88
89
90
91
92
# File 'lib/alerty/config.rb', line 88

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

.retry_intervalObject



73
74
75
76
77
# File 'lib/alerty/config.rb', line 73

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

.retry_limitObject



57
58
59
# File 'lib/alerty/config.rb', line 57

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

.retry_waitObject



61
62
63
# File 'lib/alerty/config.rb', line 61

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

.timeoutObject



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

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