lib/fasterer/file_traverser.rb in fasterer-0.1.11 vs lib/fasterer/file_traverser.rb in fasterer-0.1.12
- old
+ new
@@ -1,21 +1,23 @@
require 'pathname'
require 'colorize'
-require 'yaml'
require_relative 'analyzer'
+require_relative 'config'
module Fasterer
class FileTraverser
+ CONFIG_FILE_NAME = Config::FILE_NAME
+ SPEEDUPS_KEY = Config::SPEEDUPS_KEY
+ EXCLUDE_PATHS_KEY = Config::EXCLUDE_PATHS_KEY
- CONFIG_FILE_NAME = '.fasterer.yml'
- SPEEDUPS_KEY = 'speedups'
- EXCLUDE_PATHS_KEY = 'exclude_paths'
+ attr_reader :config
def initialize(path)
@path = Pathname(path)
@parse_error_paths = []
+ @config = Config.new
end
def traverse
if @path.directory?
scannable_files.each { |ruby_file| scan_file(ruby_file) }
@@ -23,43 +25,33 @@
scan_file(@path)
end
output_parse_errors if parse_error_paths.any?
end
- def ignored_speedups
- @ignored_speedups ||=
- config_file[SPEEDUPS_KEY].select { |_, value| value == false }.keys.map(&:to_sym)
+ def config_file
+ config.file
end
- def ignored_files
- @ignored_files ||=
- config_file[EXCLUDE_PATHS_KEY].flat_map { |path| Dir[path] }
+ def offenses_found?
+ !!offenses_found
end
- def config_file
- @config_file ||= if File.exists?(CONFIG_FILE_NAME)
- YAML.load_file(CONFIG_FILE_NAME)
- else
- nil_config_file
- end
- end
-
private
attr_reader :parse_error_paths
+ attr_accessor :offenses_found
- def nil_config_file
- { SPEEDUPS_KEY => {}, EXCLUDE_PATHS_KEY => [] }
- end
-
def scan_file(path)
analyzer = Analyzer.new(path)
analyzer.scan
rescue RubyParser::SyntaxError, Racc::ParseError, Timeout::Error
parse_error_paths.push(path)
else
- output(analyzer) if offenses_grouped_by_type(analyzer).any?
+ if offenses_grouped_by_type(analyzer).any?
+ output(analyzer)
+ self.offenses_found = true
+ end
end
def scannable_files
all_files - ignored_files
end
@@ -92,8 +84,20 @@
puts 'internal parser is not able to read some characters or'
puts 'has timed out. Unprocessable files were:'
puts '-----------------------------------------------------'
puts parse_error_paths
puts
+ end
+
+ def ignored_speedups
+ config.ignored_speedups
+ end
+
+ def ignored_files
+ config.ignored_files
+ end
+
+ def nil_config_file
+ config.nil_file
end
end
end