-
Notifications
You must be signed in to change notification settings - Fork 68
/
registry.rb
51 lines (46 loc) · 1.51 KB
/
registry.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Private: Storage of the checks which have been registered with OkComputer.
#
# No one is expected to interact directly with this class, but rather through
# the outer OkComputer interface.
module OkComputer
class Registry
# Public: Return the check registered to the given name
#
# check_name - The name of the check to retrieve
#
# Returns the registered check or raises Registry::CheckNotFound
def self.fetch(check_name)
registry.fetch(check_name)
rescue KeyError
raise CheckNotFound, "No check registered with '#{check_name}'"
end
# Public: Return an object containing all the registered checks
#
# Returns a CheckCollection instance
def self.all
CheckCollection.new registry
end
# Public: Register the given check with OkComputer
#
# check_name - The name of the check to retrieve
# check_object - Instance of Checker to register
def self.register(check_name, check_object)
check_object.registrant_name = check_name
registry[check_name] = check_object
end
# Public: Remove the check of the given name being checked
#
# check_name - The name of the check to retrieve
def self.deregister(check_name)
registry.delete(check_name)
end
# Private: The list of registered checks, keyed by their unique names
#
# Returns a Hash
def self.registry
@registry ||= {}
end
# used when fetching a check that has not been registered
CheckNotFound = Class.new(StandardError)
end
end