Class: Alerty::Config
- Inherits:
-
Object
- Object
- Alerty::Config
- Defined in:
- lib/alerty/config.rb
Class Attribute Summary collapse
-
.opts ⇒ Object
readonly
Returns the value of attribute opts.
Class Method Summary collapse
- .config ⇒ Object
- .config_path ⇒ Object
- .configure(opts) ⇒ Object
- .debug? ⇒ Boolean
- .lock_path ⇒ Object
- .log_level ⇒ Object
- .log_path ⇒ Object
- .log_shift_age ⇒ Object
- .log_shift_size ⇒ Object
- .plugins ⇒ Object
-
.reset ⇒ Object
for debug.
- .retry_interval ⇒ Object
- .retry_limit ⇒ Object
- .retry_wait ⇒ Object
- .timeout ⇒ Object
Class Attribute Details
.opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/alerty/config.rb', line 8 def opts @opts end |
Class Method Details
.config ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/alerty/config.rb', line 18 def config @config ||= begin 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_path ⇒ Object
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
61 62 63 |
# File 'lib/alerty/config.rb', line 61 def debug? !!opts[:debug] end |
.lock_path ⇒ Object
49 50 51 |
# File 'lib/alerty/config.rb', line 49 def lock_path opts[:lock_path] || config.lock_path end |
.log_level ⇒ Object
33 34 35 |
# File 'lib/alerty/config.rb', line 33 def log_level opts[:log_level] || config.log_level || 'warn' end |
.log_path ⇒ Object
29 30 31 |
# File 'lib/alerty/config.rb', line 29 def log_path opts[:log_path] || config.log_path || 'STDOUT' end |
.log_shift_age ⇒ Object
37 38 39 |
# File 'lib/alerty/config.rb', line 37 def log_shift_age opts[:log_shift_age] || config.shift_age || 0 end |
.log_shift_size ⇒ Object
41 42 43 |
# File 'lib/alerty/config.rb', line 41 def log_shift_size opts[:log_shift_size] || config.shift_size || 1048576 end |
.plugins ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/alerty/config.rb', line 71 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 |
.reset ⇒ Object
for debug
80 81 82 83 84 |
# File 'lib/alerty/config.rb', line 80 def reset @config_path = nil @config = nil @plugins = nil end |
.retry_interval ⇒ Object
65 66 67 68 69 |
# File 'lib/alerty/config.rb', line 65 def retry_interval @random ||= Random.new randomness = retry_wait * 0.125 retry_wait + @random.rand(-randomness .. randomness) end |
.retry_limit ⇒ Object
53 54 55 |
# File 'lib/alerty/config.rb', line 53 def retry_limit opts[:retry_limit] || config.retry_limit || 0 end |
.retry_wait ⇒ Object
57 58 59 |
# File 'lib/alerty/config.rb', line 57 def retry_wait opts[:retry_wait] || config.retry_wait || 1.0 end |
.timeout ⇒ Object
45 46 47 |
# File 'lib/alerty/config.rb', line 45 def timeout opts[:timeout] || config.timeout end |