lib/fasterer/file_traverser.rb in fasterer-0.1.5 vs lib/fasterer/file_traverser.rb in fasterer-0.1.6

- old
+ new

@@ -7,16 +7,21 @@ module Fasterer class FileTraverser CONFIG_FILE_NAME = '.fasterer.yml' - attr_reader :ignored_speedups + SPEEDUPS_KEY = 'speedups' + EXCLUDE_PATHS_KEY = 'exclude_paths' + + attr_reader :ignored_speedups, :ignored_paths + def initialize(path) @path = Pathname(path) @parse_error_paths = [] set_ignored_speedups + set_ignored_paths end def traverse if @path.directory? traverse_directory(@path) @@ -25,15 +30,21 @@ end output_parse_errors if parse_error_paths.any? end def set_ignored_speedups - @ignored_speedups = if config_file - config_file['speedups'].select {|_, value| value == false }.keys.map(&:to_sym) + @ignored_speedups = if config_file && config_file[SPEEDUPS_KEY] + config_file[SPEEDUPS_KEY].select {|_, value| value == false }.keys.map(&:to_sym) end || [] end + def set_ignored_paths + @ignored_paths = if config_file && config_file[EXCLUDE_PATHS_KEY] + config_file[EXCLUDE_PATHS_KEY].flat_map {|path| Dir[path] } + end || [] + end + def config_file File.exists?(CONFIG_FILE_NAME) && YAML.load_file(CONFIG_FILE_NAME) end private @@ -48,11 +59,14 @@ else output(analyzer) if offenses_grouped_by_type(analyzer).any? end def traverse_directory(path) - Dir["#{path}/**/*.rb"].each do |ruby_file| - scan_file(ruby_file.split('/').drop(1).join('/')) + Dir["#{path}/**/*.rb"].each do |ruby_file_path| + relative_ruby_file_path = Pathname(ruby_file_path).relative_path_from(path) + unless ignored_paths.include?(relative_ruby_file_path.to_s) + scan_file(relative_ruby_file_path) + end end end def output(analyzer) puts analyzer.file_path.colorize(:red)