lib/reek/source/source_locator.rb in reek-2.1.0 vs lib/reek/source/source_locator.rb in reek-2.2.0

- old
+ new

@@ -2,38 +2,37 @@ module Source # # Finds Ruby source files in a filesystem. # class SourceLocator + # Initialize with the paths we want to search. + # + # paths - a list of paths as Strings def initialize(paths) @paths = paths.map { |path| path.chomp('/') } end - def all_sources - valid_paths.map { |path| Source::SourceCode.from File.new(path) } + # Traverses all paths we initialized the SourceLocator with, finds + # all relevant ruby files and returns them as a list. + # + # Returns a list of Source::SourceCode. + def sources + find_sources.map { |pathname| Source::SourceCode.from File.new(pathname) } end private - def all_ruby_source_files(paths) + def find_sources(paths = @paths) paths.map do |path| - if test 'd', path - all_ruby_source_files(Dir["#{path}/**/*.rb"]) + pathname = Pathname.new(path) + if pathname.directory? + find_sources(Dir["#{pathname}/**/*.rb"]) else - path + next pathname if pathname.file? + $stderr.puts "Error: No such file - #{pathname}" + nil end end.flatten.sort - end - - def valid_paths - all_ruby_source_files(@paths).select do |path| - if test 'f', path - true - else - $stderr.puts "Error: No such file - #{path}" - false - end - end end end end end