Skip to content

Commit

Permalink
Add ignore_paths option to listener
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Sep 1, 2011
1 parent c922905 commit c74c9c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/guard/listener.rb
Expand Up @@ -9,8 +9,9 @@ module Guard
autoload :Polling, 'guard/listeners/polling' autoload :Polling, 'guard/listeners/polling'


class Listener class Listener
DefaultIgnorePaths = %w[. .. .bundle .git log tmp vendor]


attr_reader :directory attr_reader :directory, :ignore_paths


def self.select_and_init(*a) def self.select_and_init(*a)
if mac? && Darwin.usable? if mac? && Darwin.usable?
Expand All @@ -29,6 +30,7 @@ def initialize(directory=Dir.pwd, options={})
@directory = directory.to_s @directory = directory.to_s
@sha1_checksums_hash = {} @sha1_checksums_hash = {}
@relativize_paths = options.fetch(:relativize_paths, true) @relativize_paths = options.fetch(:relativize_paths, true)
@ignore_paths = options.fetch(:ignore_paths, DefaultIgnorePaths)
update_last_event update_last_event
end end


Expand Down Expand Up @@ -81,10 +83,8 @@ def relativize_paths?
private private


def potentially_modified_files(dirs, options={}) def potentially_modified_files(dirs, options={})
paths = Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path| paths = exclude_ignored_paths_from_dirs(dirs)
%w[. .. .bundle .git log tmp vendor].include?(File.basename(path))
end

if options[:all] if options[:all]
paths.inject([]) do |array, path| paths.inject([]) do |array, path|
if File.file?(path) if File.file?(path)
Expand All @@ -99,6 +99,12 @@ def potentially_modified_files(dirs, options={})
end end
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 # Depending on the filesystem, mtime is probably only precise to the second, so round
# both values down to the second for the comparison. # both values down to the second for the comparison.
def file_modified?(path) def file_modified?(path)
Expand Down
11 changes: 11 additions & 0 deletions spec/guard/listener_spec.rb
Expand Up @@ -160,5 +160,16 @@
end end


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 end

0 comments on commit c74c9c9

Please sign in to comment.