class OkComputer::Checks::Registry
Attributes
collection[RW]
Public Class Methods
new(collection = nil)
click to toggle source
# File lib/ok_computer/checks/registry.rb, line 16 def initialize(collection = nil) self.collection = if collection.is_a?(CheckCollection) collection elsif collection ::OkComputer::Registry.default_collection.fetch(collection) || CheckCollection.new(collection) else ::OkComputer::Registry.default_collection end end
Public Instance Methods
add(klass_or_check, check_name, *args)
click to toggle source
# File lib/ok_computer/checks/registry.rb, line 36 def add(klass_or_check, check_name, *args) register(check_name, process_check(klass_or_check, *args)) end
add_collection(collection_name, &block)
click to toggle source
# File lib/ok_computer/checks/registry.rb, line 26 def add_collection(collection_name, &block) checks = CheckCollection.new(collection_name) Checks.register(checks, &block) register(collection_name, checks) end
add_optional(klass_or_check, check_name, *args)
click to toggle source
# File lib/ok_computer/checks/registry.rb, line 32 def add_optional(klass_or_check, check_name, *args) add(OptionalCheck.new(process_check(klass_or_check, *args)), check_name) end
Private Instance Methods
build_check(klass, *args)
click to toggle source
# File lib/ok_computer/checks/registry.rb, line 48 def build_check(klass, *args) unless klass.is_a?(Class) begin klass = OkComputer.const_get("#{klass}_check".camelize) rescue NameError raise LoadError, "Could not register #{klass.inspect}." end end klass.new(*args) end
process_check(klass_or_check, *args)
click to toggle source
# File lib/ok_computer/checks/registry.rb, line 42 def process_check(klass_or_check, *args) return klass_or_check if [OptionalCheck, Check, CheckCollection].any? { |k| klass_or_check.is_a?(k) } build_check(klass_or_check, *args) end