Class: Updawg::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/updawg/checks/check.rb

Direct Known Subclasses

DeviationCheck, ThresholdCheck

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Check

Returns a new instance of Check.



16
17
18
19
20
# File 'lib/updawg/checks/check.rb', line 16

def initialize(name, options = {}, &block)
  @name = name
  @block = block
  @timeout = options.delete(:timeout) || Updawg.configuration.timeout
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/updawg/checks/check.rb', line 14

def name
  @name
end

Instance Method Details

#error(message = nil) ⇒ Object



38
39
40
# File 'lib/updawg/checks/check.rb', line 38

def error(message = nil)
  Updawg::Result.new(name, :error, message)
end

#error!(message = nil) ⇒ Object

Raises:



50
51
52
# File 'lib/updawg/checks/check.rb', line 50

def error!(message = nil)
  raise ResultException.new(Updawg::Result.new(name, :error, message))
end

#pass(message = nil) ⇒ Object



30
31
32
# File 'lib/updawg/checks/check.rb', line 30

def pass(message = nil)
  Updawg::Result.new(name, :pass, message)
end

#pass!(message = nil) ⇒ Object

Raises:



42
43
44
# File 'lib/updawg/checks/check.rb', line 42

def pass!(message = nil)
  raise ResultException.new(Updawg::Result.new(name, :pass, message))
end

#performObject



22
23
24
25
26
27
28
# File 'lib/updawg/checks/check.rb', line 22

def perform
  result = execute_check
  return result if result.kind_of?(Result)
  pass
rescue RuntimeError => e
  error e.message
end

#warning(message = nil) ⇒ Object



34
35
36
# File 'lib/updawg/checks/check.rb', line 34

def warning(message = nil)
  Updawg::Result.new(name, :warning, message)
end

#warning!(message = nil) ⇒ Object

Raises:



46
47
48
# File 'lib/updawg/checks/check.rb', line 46

def warning!(message = nil)
  raise ResultException.new(Updawg::Result.new(name, :warning, message))
end