class Remon::CheckDsl
Public Class Methods
new(load_paths = [])
click to toggle source
# File lib/remon/check_dsl.rb, line 9 def initialize(load_paths = []) @load_paths = load_paths @checks = {} end
Public Instance Methods
check(name)
click to toggle source
# File lib/remon/check_dsl.rb, line 26 def check(name) name = name.to_s validate_name(name) @checks[name] || load_check(name) end
defcheck(name = nil, &block)
click to toggle source
# File lib/remon/check_dsl.rb, line 14 def defcheck(name = nil, &block) return define_klass(&block) if not name name = name.to_s validate_name(name) if @checks[name] raise Error, "check #{name} already defined" end klass = define_klass(&block) klass.name = name @checks[name] = klass end
proc_check(name = nil, &block)
click to toggle source
# File lib/remon/check_dsl.rb, line 32 def proc_check(name = nil, &block) ProcCheck.new(name, block) end
Private Instance Methods
check_files(name)
click to toggle source
# File lib/remon/check_dsl.rb, line 77 def check_files(name) files = [] if name.include? ":" part = name.partition(":") namespace = part[0] rest = part[2] files << "#{namespace}/#{rest}.rb" files << "#{namespace}.rb" else files << "#{name}.rb" end files end
define_klass(&block)
click to toggle source
# File lib/remon/check_dsl.rb, line 48 def define_klass(&block) Class.new(Check, &block) end
find_check_file(name)
click to toggle source
# File lib/remon/check_dsl.rb, line 66 def find_check_file(name) files = check_files(name) combination = files.product(@load_paths).find { |f, d| Dir.glob("#{d}/#{f}").first } if not combination raise Error, "unable to find check: #{name} in PATH: #{@load_paths.join(":")}" end dir = combination[1] file = combination[0] path = "#{dir}/#{file}" end
load_check(name)
click to toggle source
# File lib/remon/check_dsl.rb, line 56 def load_check(name) file = find_check_file(name) load_file file if a = @checks[name] return a else raise Error, "unable to find check: #{name} in #{file}" end end
load_file(f)
click to toggle source
# File lib/remon/check_dsl.rb, line 52 def load_file(f) instance_eval File.read(f), f end
validate_name(name)
click to toggle source
# File lib/remon/check_dsl.rb, line 38 def validate_name(name) regex = /\A[a-zA-Z0-9_:]+\z/ if not name =~ regex raise Error, "only alphanumeric, _, : characters allowed for check name" end if name.scan(/:/).size > 1 raise Error, "nested namespacing not allowed in check names" end end