class Pedant::Check
Attributes
result[R]
Public Class Methods
all()
click to toggle source
# File lib/pedant/check.rb, line 61 def self.all (@_all ||= []) end
depends()
click to toggle source
# File lib/pedant/check.rb, line 83 def self.depends keys = self.requires Check.all.reject do |cls| (cls.provides & keys).empty? end end
friendly_name()
click to toggle source
# File lib/pedant/check.rb, line 145 def self.friendly_name # Mangle the class name to be more user-friendly. self.name.gsub(/.*::/, '').gsub(/^Check/, '').gsub(/[A-Z][^A-Z]*/, ' \&').strip end
inherited(cls)
click to toggle source
# File lib/pedant/check.rb, line 65 def self.inherited(cls) all << cls end
initialize!()
click to toggle source
# File lib/pedant/check.rb, line 42 def self.initialize! Dir.glob(Pedant.lib + 'pedant/checks/*.rb').each { |f| load(f) } end
list()
click to toggle source
# File lib/pedant/check.rb, line 57 def self.list all.map{ |cls| cls.friendly_name }.sort end
new(kb)
click to toggle source
# File lib/pedant/check.rb, line 46 def initialize(kb) @report = [] @result = :void @kb = kb # Run all the dependencies for this check if we're in test mode. return unless @kb[:test_mode] Check.run_checks_in_dependency_order(kb, self.class.depends) end
provides()
click to toggle source
# File lib/pedant/check.rb, line 69 def self.provides return [] end
ready?(kb)
click to toggle source
# File lib/pedant/check.rb, line 77 def self.ready?(kb) self.requires.reduce(true) do |stat, req| stat && kb.has_key?(req) end end
requires()
click to toggle source
# File lib/pedant/check.rb, line 73 def self.requires return [] end
run_checks_in_dependency_order(kb, checks)
click to toggle source
# File lib/pedant/check.rb, line 91 def self.run_checks_in_dependency_order(kb, checks) # Try to run each pending check, until we've run all our checks or # deadlocked. fatal = false run_checks = [] until checks.empty? || fatal # Find all of the checks that can run right now. ready = checks.select { |cls| cls.ready?(kb) } break if ready.empty? # Run all of the checks that are ready. ready.each do |cls| # Create a new check instance. chk = cls.new(kb) checks.delete(cls) chk.run # Yield the results of the finished check run_checks << chk # Fatal errors mean that no further checks should be processed. if chk.result == :fatal fatal = true break end end end run_checks end
Public Instance Methods
fail()
click to toggle source
# File lib/pedant/check.rb, line 150 def fail @result = :fail end
fatal()
click to toggle source
# File lib/pedant/check.rb, line 154 def fatal report(:error, "This is a fatal error.") @result = :fatal end
pass()
click to toggle source
# File lib/pedant/check.rb, line 159 def pass @result = :pass end
report(level, text=nil)
click to toggle source
# File lib/pedant/check.rb, line 122 def report(level, text=nil) unless text.nil? if @@levels.index(level).nil? raise "Reporting level #{level} is not known." end @report << [level, text] return end # Convert level from symbol to an array index. level = @@levels.index(level) if level.is_a?(Symbol) # Format all components of a report at or below the specified level. msg = @report.select { |l, t| @@levels.index(l) <= level }.map { |l, t| t }.join("\n") msg << "\n" unless msg.empty? # Format the check's result. msg = "[#{@@statuses[@result]}] #{self.class.friendly_name}\n#{msg}" return msg end
skip()
click to toggle source
# File lib/pedant/check.rb, line 163 def skip @result = :skip end
warn()
click to toggle source
# File lib/pedant/check.rb, line 167 def warn @result = :warn end