Class: HealthBit::Check
- Inherits:
-
Object
- Object
- HealthBit::Check
- Defined in:
- lib/health_bit/check.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call(env = {}) ⇒ nil, CheckError
-
#initialize(name, handler) ⇒ Check
constructor
A new instance of Check.
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
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
5 6 7 |
# File 'lib/health_bit/check.rb', line 5 def handler @handler end |
#name ⇒ Object (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
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 |