Class: MiniCheck::Check
- Inherits:
-
Object
- Object
- MiniCheck::Check
- Defined in:
- lib/mini_check/check.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#healthy ⇒ Object
Returns the value of attribute healthy.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #healthy? ⇒ Boolean
-
#initialize(args = {}, &block) ⇒ Check
constructor
A new instance of Check.
- #run ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(args = {}, &block) ⇒ Check
Returns a new instance of Check.
8 9 10 11 12 13 |
# File 'lib/mini_check/check.rb', line 8 def initialize args = {}, &block args = {name: args} if !args.is_a?(Hash) args[:action] = block if block_given? set_attributes args end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/mini_check/check.rb', line 5 def action @action end |
#exception ⇒ Object
Returns the value of attribute exception.
6 7 8 |
# File 'lib/mini_check/check.rb', line 6 def exception @exception end |
#healthy ⇒ Object
Returns the value of attribute healthy.
4 5 6 |
# File 'lib/mini_check/check.rb', line 4 def healthy @healthy end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/mini_check/check.rb', line 3 def name @name end |
Instance Method Details
#healthy? ⇒ Boolean
15 16 17 |
# File 'lib/mini_check/check.rb', line 15 def healthy? !!healthy end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/mini_check/check.rb', line 19 def run begin self.healthy = action.call self.exception = nil rescue Exception => e self.healthy = false self.exception = e end end |
#to_hash ⇒ Object
29 30 31 32 33 34 |
# File 'lib/mini_check/check.rb', line 29 def to_hash {}.tap do |h| h[:healthy] = healthy? h[:error] = {message: exception., stack: exception.backtrace} if exception end end |