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.



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

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#exceptionObject

Returns the value of attribute exception.



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

def exception
  @exception
end

#healthyObject

Returns the value of attribute healthy.



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

def healthy
  @healthy
end

#nameObject

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

Returns:

  • (Boolean)


15
16
17
# File 'lib/mini_check/check.rb', line 15

def healthy?
  !!healthy
end

#runObject



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_hashObject



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.message, stack: exception.backtrace} if exception
  end
end