class Reek::Source::SourceLocator
Finds Ruby source files in a filesystem.
Attributes
Public Class Methods
Source
# File lib/reek/source/source_locator.rb, line 15 def initialize(paths, configuration: Configuration::AppConfiguration.default, options: Reek::CLI::Options.new) @options = options @paths = paths.flat_map do |string| path = Pathname.new(string) current_directory?(path) ? path.entries : path end @configuration = configuration end
Initialize with the paths we want to search.
paths - a list of paths as Strings
Public Instance Methods
Source
# File lib/reek/source/source_locator.rb, line 28 def sources source_paths end
Traverses all paths we initialized the SourceLocator
with, finds all relevant Ruby files and returns them as a list.
@return [Array<Pathname>] Ruby paths found
Private Instance Methods
Source
# File lib/reek/source/source_locator.rb, line 94 def current_directory?(path) [Pathname.new('.'), Pathname.new('./')].include?(path) end
@quality :reek:UtilityFunction
Source
# File lib/reek/source/source_locator.rb, line 58 def ignore_file?(path) if options.force_exclusion? path.ascend do |ascendant| break true if path_excluded?(ascendant) false end else path_excluded?(path) end end
Source
# File lib/reek/source/source_locator.rb, line 84 def ignore_path?(path) path_excluded?(path) || hidden_directory?(path) end
Source
# File lib/reek/source/source_locator.rb, line 70 def path_excluded?(path) configuration.path_excluded?(path) end
Source
# File lib/reek/source/source_locator.rb, line 75 def print_no_such_file_error(path) warn "Error: No such file - #{path}" end
@quality :reek:UtilityFunction
Source
# File lib/reek/source/source_locator.rb, line 89 def ruby_file?(path) path.extname == '.rb' end
@quality :reek:UtilityFunction
Source
# File lib/reek/source/source_locator.rb, line 46 def source_files_from_path(given_path) relevant_paths = [] given_path.find do |path| if path.directory? Find.prune if ignore_path?(path) elsif ruby_file?(path) relevant_paths << path unless ignore_file?(path) end end relevant_paths end
Source
# File lib/reek/source/source_locator.rb, line 36 def source_paths paths.each_with_object([]) do |given_path, relevant_paths| if given_path.exist? relevant_paths.concat source_files_from_path(given_path) else print_no_such_file_error(given_path) end end end