diff --git a/lib/guard/listener.rb b/lib/guard/listener.rb index 1a8eeaf4f..7dbe3cbdd 100644 --- a/lib/guard/listener.rb +++ b/lib/guard/listener.rb @@ -9,8 +9,9 @@ module Guard autoload :Polling, 'guard/listeners/polling' class Listener + DefaultIgnorePaths = %w[. .. .bundle .git log tmp vendor] - attr_reader :directory + attr_reader :directory, :ignore_paths def self.select_and_init(*a) if mac? && Darwin.usable? @@ -29,6 +30,7 @@ def initialize(directory=Dir.pwd, options={}) @directory = directory.to_s @sha1_checksums_hash = {} @relativize_paths = options.fetch(:relativize_paths, true) + @ignore_paths = options.fetch(:ignore_paths, DefaultIgnorePaths) update_last_event end @@ -81,10 +83,8 @@ def relativize_paths? private def potentially_modified_files(dirs, options={}) - paths = Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path| - %w[. .. .bundle .git log tmp vendor].include?(File.basename(path)) - end - + paths = exclude_ignored_paths_from_dirs(dirs) + if options[:all] paths.inject([]) do |array, path| if File.file?(path) @@ -99,6 +99,12 @@ def potentially_modified_files(dirs, options={}) end end + def exclude_ignored_paths_from_dirs(dirs) + paths = Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path| + @ignore_paths.include?(File.basename(path)) + end + end + # Depending on the filesystem, mtime is probably only precise to the second, so round # both values down to the second for the comparison. def file_modified?(path) diff --git a/spec/guard/listener_spec.rb b/spec/guard/listener_spec.rb index e9ae26b34..313203016 100644 --- a/spec/guard/listener_spec.rb +++ b/spec/guard/listener_spec.rb @@ -160,5 +160,16 @@ end end + + describe "#ignore_paths" do + it "defaults to the default ignore paths" do + subject.new.ignore_paths.should == Guard::Listener::DefaultIgnorePaths + end + + it "can be set via :ignore_paths option" do + listener = subject.new 'path', :ignore_paths => ['foo', 'bar'] + listener.ignore_paths.should == ['foo', 'bar'] + end + end end