lib/roodi/core/runner.rb in roodi-3.2.0 vs lib/roodi/core/runner.rb in roodi-3.3.0

- old
+ new

@@ -6,29 +6,55 @@ require 'roodi/core/visitable_sexp' module Roodi module Core class Runner - DEFAULT_CONFIG = File.join(File.dirname(__FILE__), "..", "..", "..", "roodi.yml") - attr_writer :config attr_reader :files_checked def initialize(*checks) - @config = DEFAULT_CONFIG + @config = default_config @checks = checks unless checks.empty? end + def default_config + project_config ? project_config : roodi_gem_config + end + + def roodi_gem_config + File.join(File.dirname(__FILE__), "..", "..", "..", "roodi.yml") + end + + def project_config + File.exists?("roodi.yml") ? "roodi.yml" : nil + end + def start(paths) + puts "\nRunning Roodi checks" + paths = ['.'] if paths == [] all_files = collect_files(paths) @files_checked = all_files.count all_files.each do |path| check_file(path) end + + output_result(errors, @files_checked) end + def output_result(errors, files_checked) + errors.each {|error| puts "\e[31m#{error}\e[0m"} + + puts "\nChecked #{files_checked} files" + result = "Found #{errors.size} errors." + if errors.empty? + puts "\e[32m#{result}\e[0m" + else + raise "\e[31m#{result}\e[0m" + end + end + def collect_files(paths) files = [] paths.each do |path| if File.file?(path) files << path @@ -94,16 +120,19 @@ @parsing_errors ||= [] end def load_checks check_objects = [] - checks = YAML.load_file @config + checks = load_config(@config) checks.each do |check_class_name, options| check_class = Roodi::Checks.const_get(check_class_name) check_objects << check_class.make(options || {}) end check_objects end + def load_config(config_file) + YAML.load_file config_file + end end end end