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.
-
#time ⇒ Object
Returns the value of attribute time.
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.
11 12 13 14 15 16 |
# File 'lib/mini_check/check.rb', line 11 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.
7 8 9 |
# File 'lib/mini_check/check.rb', line 7 def action @action end |
#exception ⇒ Object
Returns the value of attribute exception.
9 10 11 |
# File 'lib/mini_check/check.rb', line 9 def exception @exception end |
#healthy ⇒ Object
Returns the value of attribute healthy.
6 7 8 |
# File 'lib/mini_check/check.rb', line 6 def healthy @healthy end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/mini_check/check.rb', line 5 def name @name end |
#time ⇒ Object
Returns the value of attribute time.
8 9 10 |
# File 'lib/mini_check/check.rb', line 8 def time @time end |
Instance Method Details
#healthy? ⇒ Boolean
18 19 20 |
# File 'lib/mini_check/check.rb', line 18 def healthy? !!healthy end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mini_check/check.rb', line 22 def run self.time = Benchmark.measure do begin do_run self.exception = nil rescue Exception => e self.healthy = false self.exception = e end end.real end |
#to_hash ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/mini_check/check.rb', line 34 def to_hash {}.tap do |h| h[:healthy] = healthy? h[:time] = time h[:error] = error_hash if exception end end |