Class: OkComputer::Registry

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

Constant Summary collapse

CheckNotFound =

used when fetching a check that has not been registered

Class.new(StandardError)
CollectionNotFound =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.allObject

Public: Return an object containing all the registered checks

Returns the default_collection CheckCollection instance



21
22
23
# File 'lib/ok_computer/registry.rb', line 21

def self.all
  default_collection
end

.default_collectionObject

Public: The default collection of checks

Returns @default_collection



33
34
35
# File 'lib/ok_computer/registry.rb', line 33

def self.default_collection
  @default_collection ||= CheckCollection.new('Default Collection', true)
end

.deregister(check_name, collection_name = nil) ⇒ Object

Public: Remove the check of the given name being checked

check_name - The name of the check to retrieve collection_name - The name of the check collection the check should be deregistered from



69
70
71
# File 'lib/ok_computer/registry.rb', line 69

def self.deregister(check_name, collection_name=nil)
  find_collection(collection_name).deregister(check_name)
end

.fetch(name) ⇒ Object

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



12
13
14
15
16
# File 'lib/ok_computer/registry.rb', line 12

def self.fetch(name)
  default_collection.fetch(name)
rescue KeyError
  raise CheckNotFound, "No matching check"
end

.register(check_name, check_object, collection_name = nil, options = {}) ⇒ Object

Public: Register the given check with OkComputer

check_name - The name of the check to retrieve check_object - Instance of Checker to register collection_name - The name of the check collection the check should be registered to options - Set skip_all to true to omit the check from the default collection's results



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ok_computer/registry.rb', line 43

def self.register(check_name, check_object, collection_name=nil, options={})
  if collection_name.is_a?(Hash)
    options = collection_name
    collection_name = nil
  end

  if collection_name && options[:skip_all]
    raise ArgumentError, "skip_all is only supported in the default collection"
  end

  if !collection_name && options.key?(:skip_all)
    if check_object.respond_to?(:skip_all=)
      check_object.skip_all = !!options[:skip_all]
    elsif options[:skip_all]
      raise ArgumentError, "skip_all requires a check that supports skip_all="
    end
  end

  collection = find_collection(collection_name)
  collection.register(check_name, check_object)
end