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
- .dotenv? ⇒ 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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, 'plugin' => yaml['plugins'], }.to_yaml) end @config 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
84 85 86 |
# File 'lib/alerty/config.rb', line 84 def debug? !!opts[:debug] end |
.dotenv? ⇒ Boolean
88 89 90 |
# File 'lib/alerty/config.rb', line 88 def dotenv? !!opts[:dotenv] end |
.lock_path ⇒ Object
72 73 74 |
# File 'lib/alerty/config.rb', line 72 def lock_path opts[:lock_path] || config.lock_path end |
.log_level ⇒ Object
54 55 56 |
# File 'lib/alerty/config.rb', line 54 def log_level opts[:log_level] || config.log_level || 'warn' end |
.log_path ⇒ Object
50 51 52 |
# File 'lib/alerty/config.rb', line 50 def log_path opts[:log_path] || config.log_path || 'STDOUT' end |
.log_shift_age ⇒ Object
58 59 60 61 |
# 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 ⇒ Object
63 64 65 66 |
# 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 ⇒ Object
98 99 100 |
# File 'lib/alerty/config.rb', line 98 def plugins @plugins ||= config.fetch('plugins') end |
.reset ⇒ Object
for debug
103 104 105 106 107 |
# File 'lib/alerty/config.rb', line 103 def reset @config_path = nil @config = nil @plugins = nil end |
.retry_interval ⇒ Object
92 93 94 95 96 |
# 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 ⇒ Object
76 77 78 |
# File 'lib/alerty/config.rb', line 76 def retry_limit opts[:retry_limit] || config.retry_limit || 0 end |
.retry_wait ⇒ Object
80 81 82 |
# File 'lib/alerty/config.rb', line 80 def retry_wait opts[:retry_wait] || config.retry_wait || 1.0 end |
.timeout ⇒ Object
68 69 70 |
# File 'lib/alerty/config.rb', line 68 def timeout opts[:timeout] || config.timeout end |