Class: Rack::ECG::CheckRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rack/ecg/check_registry.rb

Constant Summary collapse

CheckNotRegistered =

Raised when a check didn’t exist during lookup

Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCheckRegistry

Constructs the singleton instance of the registry



13
14
15
# File 'lib/rack/ecg/check_registry.rb', line 13

def initialize
  @registry = {}
end

Class Method Details

.lookup(name) ⇒ Object

Fetches the registered check class by name

Parameters:

  • name (Symbol)

    Registered check name

Raises:



35
36
37
# File 'lib/rack/ecg/check_registry.rb', line 35

def lookup(name)
  instance.lookup(name)
end

.register(name, check_class) ⇒ Object

Register a check class by name

Parameters:

  • name (Symbol)

    Desired check name

  • check_class (Class)

    Class implementing check functionality



40
41
42
# File 'lib/rack/ecg/check_registry.rb', line 40

def register(name, check_class)
  instance.register(name, check_class)
end

Instance Method Details

#lookup(name) ⇒ Object

Fetches the registered check class by name

Parameters:

  • name (Symbol)

    Registered check name

Raises:



29
30
31
# File 'lib/rack/ecg/check_registry.rb', line 29

def lookup(name)
  @registry.fetch(name) { raise CheckNotRegistered, "Check '#{name}' is not registered" }
end

#register(name, check_class) ⇒ Object

Register a check class by name

Parameters:

  • name (Symbol)

    Desired check name

  • check_class (Class)

    Class implementing check functionality



21
22
23
# File 'lib/rack/ecg/check_registry.rb', line 21

def register(name, check_class)
  @registry[name] = check_class
end