Class: Leafy::Health::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/leafy/health/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



10
11
12
# File 'lib/leafy/health/registry.rb', line 10

def initialize
  @health = com.codahale.metrics.health.HealthCheckRegistry.new
end

Instance Attribute Details

#healthObject (readonly)

state ofthe registry



8
9
10
# File 'lib/leafy/health/registry.rb', line 8

def health
  @health
end

Instance Method Details

#namesArray<String>

the names of all registered HealthCheck

Returns:

  • (Array<String>)

    names of HealthCheck in order of their registration



42
43
44
# File 'lib/leafy/health/registry.rb', line 42

def names
  @health.names.to_a
end

#register(name, check = nil) {|which| ... } ⇒ Object

register a HealthCheck under a given name

Parameters:

  • name (String)
  • instead (String)

    of block any check object which responds to ‘call’

Yield Parameters:

  • which (HealthCheckRegistry::HealthCheck)

    has convienient methods to create healthy and unhealthy results with message

Yield Returns:

  • (String)

    if the healthcheck fails return the message

  • (NilClass)

    if the healthcheck succeeds

  • (com.codahale.metrics.health.HealthCheck::Result)

    if the check produces its own result object



22
23
24
25
26
27
28
29
30
# File 'lib/leafy/health/registry.rb', line 22

def register(name, check = nil, &block )
  if check and not block_given? and check.is_a? com.codahale.metrics.health.HealthCheck
    @health.register( name, check )
  elsif check.nil? and block_given?
    @health.register( name, HealthCheck.new( &block ) )
  else
    raise 'needs either a block and object with call method'
  end
end

#unregister(name) ⇒ Object

unregister a HealthCheck for a given name

Parameters:

  • name (String)


35
36
37
# File 'lib/leafy/health/registry.rb', line 35

def unregister(name)
  @health.unregister(name)
end