Class: Rack::ECG::CheckRegistry
- Inherits:
-
Object
- Object
- Rack::ECG::CheckRegistry
- 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
-
.lookup(name) ⇒ Object
Fetches the registered check class by name.
-
.register(name, check_class) ⇒ Object
Register a check class by name.
Instance Method Summary collapse
-
#initialize ⇒ CheckRegistry
constructor
Constructs the singleton instance of the registry.
-
#lookup(name) ⇒ Object
Fetches the registered check class by name.
-
#register(name, check_class) ⇒ Object
Register a check class by name.
Constructor Details
#initialize ⇒ CheckRegistry
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
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
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
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
21 22 23 |
# File 'lib/rack/ecg/check_registry.rb', line 21 def register(name, check_class) @registry[name] = check_class end |