Class: HealthBit::Check

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, handler) ⇒ Check

Returns a new instance of Check.



7
8
9
10
# File 'lib/health_bit/check.rb', line 7

def initialize(name, handler)
  @name = name
  @handler = handler
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



5
6
7
# File 'lib/health_bit/check.rb', line 5

def handler
  @handler
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/health_bit/check.rb', line 5

def name
  @name
end

Instance Method Details

#call(env = {}) ⇒ nil, CheckError

Returns:



14
15
16
17
18
19
20
21
# File 'lib/health_bit/check.rb', line 14

def call(env = {})
  arity = handler.is_a?(Proc) ? handler.arity : handler.method(:call).arity
  return if arity.abs == 1 ? handler.call(env) : handler.call

  raise('The check has returned a negative value')
rescue Exception => e # rubocop:disable Lint/RescueException
  CheckError.new(name, exception: e)
end