Class: WebMonitor::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/web-monitor/config.rb

Constant Summary collapse

DEFAULTS =
{
  response_time_limit: 3.0,
  alert_mail: nil,
  urls_file: 'urls.csv',
  log_file: 'web-monitor.log',
  delay: 1.0,
}

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Config

Returns a new instance of Config.



14
15
16
17
# File 'lib/web-monitor/config.rb', line 14

def initialize(config_file)
  struct = YAML::load(File.open(config_file))
  @config = OpenStruct.new(struct)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/web-monitor/config.rb', line 19

def method_missing(method, *args, &block)
  out = @config.send(method)
  if out.nil?
    return DEFAULTS[method]
  else
    case method
    when :response_time_limit
      out.to_f
    when :delay
      out.to_f
    else
      out
    end
  end
end