Class: Reckoner
- Inherits:
-
Object
- Object
- Reckoner
- Defined in:
- lib/reckoner.rb
Overview
The Reckoner class is intialized with the configuration information, loads the checks and performs them.
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#check(check_hash) ⇒ Object
Goes through the passed in check hash and begins the checking process.
-
#initialize(custom_check_files = nil, debug = false) ⇒ Reckoner
constructor
Creates the class.
-
#load_checks(custom_check_files) ⇒ Object
Loads the checks from the standard_checks file and the.
Constructor Details
#initialize(custom_check_files = nil, debug = false) ⇒ Reckoner
Creates the class. The first argument is an array of custom check files, if any. The debug arguments determines whether or not debugging information will be printed out during execution.
14 15 16 17 18 19 |
# File 'lib/reckoner.rb', line 14 def initialize(custom_check_files = nil,debug = false) @debug = debug @errors = [] @registered_checks = {} load_checks(custom_check_files) end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
8 9 10 |
# File 'lib/reckoner.rb', line 8 def debug @debug end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/reckoner.rb', line 9 def errors @errors end |
Instance Method Details
#check(check_hash) ⇒ Object
Goes through the passed in check hash and begins the checking process. Ensures that the files exist before the other checks are called.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/reckoner.rb', line 37 def check(check_hash) unless check_hash raise "No checks to perform - check that your configuration " + "file is formatted correctly" return end default_checks = check_hash.delete('default_check') || {} puts "Using defaults: #{default_checks.inspect}" if @debug && !default_checks.empty? check_hash.each do |block,checks| puts "\n'#{block}'" if @debug checks = default_checks.merge(checks) puts " checks: #{checks.inspect}" if @debug files = checks.delete('files') || checks.delete('file') unless files raise "No file entries found in block '#{block}'" end base_path = checks.delete('base_path') files = [files] unless files.is_a? Array files.each do |f| if base_path file_path = File.join(base_path,f.strip) else file_path = f.strip end if File.exists?(file_path) && File.readable?(file_path) puts " Checking file '#{file_path}'" if @debug run_checks(block,file_path,checks) else @errors << "Reckoner found a problem with '#{file_path}': file " + "does not exist or is not readable by this user" end end end end |
#load_checks(custom_check_files) ⇒ Object
Loads the checks from the standard_checks file and the
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/reckoner.rb', line 22 def load_checks(custom_check_files) #load the standard checks require 'standard_checks.rb' #load the custom check files from the arguments custom_check_files.each{|f| require f } if custom_check_files AbstractCheck.children.each do |chk| @registered_checks[chk.get_check_name] = chk end end |