class MiniCheck::Check

Attributes

action[RW]
exception[RW]
healthy[RW]
name[RW]
time[RW]

Public Class Methods

new(args = {}) click to toggle source
# 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

Public Instance Methods

healthy?() click to toggle source
# File lib/mini_check/check.rb, line 18
def healthy?
  !!healthy
end
run() click to toggle source
# 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() click to toggle source
# 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

Private Instance Methods

do_run() click to toggle source
# File lib/mini_check/check.rb, line 44
def do_run
  self.healthy = action.call
end
error_hash() click to toggle source
# File lib/mini_check/check.rb, line 48
def error_hash
  {
    message: exception.message,
    stack: exception.backtrace
  }
end
set_attributes(args = {}) click to toggle source
# File lib/mini_check/check.rb, line 55
def set_attributes args = {}
  args.each do |k,v|
    send("#{k}=", v)
  end
end