Permalink
Browse files

Add ignore_paths option to listener

  • Loading branch information...
1 parent c922905 commit c74c9c9bf975e44c344dd50efbb4f4d71e18d2d4 @ianwhite ianwhite committed Sep 1, 2011
Showing with 22 additions and 5 deletions.
  1. +11 −5 lib/guard/listener.rb
  2. +11 −0 spec/guard/listener_spec.rb
View
16 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)
View
11 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

0 comments on commit c74c9c9

Please sign in to comment.