Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Don't glob when no directories are specified.
Browse files Browse the repository at this point in the history
Before this commit when no directories were specified for the FileScanner class
(or no existing ones) the code would end up globbing for /**/*.rb. That is, it
would search for all Ruby source files starting in the root directory of your
disk. Yikes.

This commit fixes this by simply not globbing at all if the list of directories
is empty.

See #83 and #84 for more information.
  • Loading branch information
Yorick Peterse committed Dec 23, 2013
1 parent 64cd717 commit d8b734a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/ruby-lint/file_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def initialize(directories = self.class.default_directories, ignore = [])
# @return [Array]
#
def scan(constant)
# Globbing all files at once and then comparing those results is faster
# than running a Dir.glob for every call to #scan.
@glob_cache ||= Dir.glob("#{directories.join(',')}/**/*.rb")
@glob_cache ||= directories.empty? ? [] : glob_ruby_files

unless constant_paths_cached?(constant)
build_constant_paths_cache(constant)
Expand All @@ -73,6 +71,13 @@ def scan(constant)

private

##
# @return [Array]
#
def glob_ruby_files
return Dir.glob("#{directories.join(',')}/**/*.rb")
end

##
# Searches all the files that could potentially define the given constant
# and caches them.
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby-lint/file_scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@

scanner.scan('Example::User').empty?.should == true
end

example 'do not scan when there are no directories' do
scanner = RubyLint::FileScanner.new([])

scanner.should_not receive(:glob_ruby_files)

scanner.scan('Foo')
end
end

0 comments on commit d8b734a

Please sign in to comment.