Class: MiniCheck::Check

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#exceptionObject

Returns the value of attribute exception.



9
10
11
# File 'lib/mini_check/check.rb', line 9

def exception
  @exception
end

#healthyObject

Returns the value of attribute healthy.



6
7
8
# File 'lib/mini_check/check.rb', line 6

def healthy
  @healthy
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#timeObject

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/mini_check/check.rb', line 18

def healthy?
  !!healthy
end

#runObject



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_hashObject



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