Replacing default ignore and filter patterns, instead of adding to them #68

Merged
merged 3 commits into from Nov 21, 2012
@@ -88,6 +88,17 @@ def ignore(*regexps)
@ignoring_patterns.merge(regexps)
end
+ # Replaces ignoring patterns in the record.
+ #
+ # @example Ignore only these paths
+ # ignore! %r{^ignored/path/}, /man/
+ #
+ # @param [Regexp] regexp a pattern for ignoring paths
+ #
+ def ignore!(*regexps)
+ @ignoring_patterns.replace(regexps)
+ end
+
# Adds filtering patterns to the listener.
#
# @example Filter some files
@@ -99,6 +110,17 @@ def filter(*regexps)
@filtering_patterns.merge(regexps)
end
+ # Replaces filtering patterns in the listener.
+ #
+ # @example Filter only these files
+ # ignore /\.txt$/, /.*\.zip/
+ #
+ # @param [Regexp] regexp a pattern for filtering paths
+ #
+ def filter!(*regexps)
+ @filtering_patterns.replace(regexps)
+ end
+
# Returns whether a path should be ignored or not.
#
# @param [String] path the path to test.
@@ -93,6 +93,17 @@ def ignore(*regexps)
self
end
+ # Replaces ignoring patterns in the listener.
+ #
+ # @param (see Listen::DirectoryRecord#ignore!)
+ #
+ # @return [Listen::Listener] the listener
+ #
+ def ignore!(*regexps)
+ @directory_record.ignore!(*regexps)
+ self
+ end
+
# Adds filtering patterns to the listener.
#
# @param (see Listen::DirectoryRecord#filter)
@@ -104,6 +115,17 @@ def filter(*regexps)
self
end
+ # Replacing filtering patterns in the listener.
+ #
+ # @param (see Listen::DirectoryRecord#filter!)
+ #
+ # @return [Listen::Listener] the listener
+ #
+ def filter!(*regexps)
+ @directory_record.filter!(*regexps)
+ self
+ end
+
# Sets the latency for the adapter. This is a helper method
# to simplify changing the latency directly from the listener.
#
@@ -65,6 +65,17 @@ def ignore(*paths)
self
end
+ # Replaces ignored paths in the listener.
+ #
+ # @param (see Listen::DirectoryRecord#ignore!)
+ #
+ # @return [Listen::Listener] the listener
+ #
+ def ignore!(*paths)
+ @directories_records.each { |r| r.ignore!(*paths) }
+ self
+ end
+
# Adds file filters to the listener.
#
# @param (see Listen::DirectoryRecord#filter)
@@ -76,6 +87,17 @@ def filter(*regexps)
self
end
+ # Replaces file filters in the listener.
+ #
+ # @param (see Listen::DirectoryRecord#filter!)
+ #
+ # @return [Listen::Listener] the listener
+ #
+ def filter!(*regexps)
+ @directories_records.each { |r| r.filter!(*regexps) }
+ self
+ end
+
# Runs the callback passing it the changes if there are any.
#
# @param (see Listen::DirectoryRecord#fetch_changes)
@@ -41,19 +41,33 @@
end
describe '#ignore' do
- it 'adds the passed paths to the list of ignoted paths in the record' do
+ it 'adds the passed paths to the list of ignored paths in the record' do
subject.ignore(%r{^\.old/}, %r{\.pid$})
subject.ignoring_patterns.should include(%r{^\.old/}, %r{\.pid$})
end
end
+ describe '#ignore!' do
+ it 'replace the ignored paths in the record' do
+ subject.ignore!(%r{^\.old/}, %r{\.pid$})
+ subject.ignoring_patterns.should =~ [%r{^\.old/}, %r{\.pid$}]
+ end
+ end
+
describe '#filter' do
it 'adds the passed regexps to the list of filters that determine the stored paths' do
subject.filter(%r{\.(?:jpe?g|gif|png)}, %r{\.(?:mp3|ogg|a3c)})
subject.filtering_patterns.should include(%r{\.(?:jpe?g|gif|png)}, %r{\.(?:mp3|ogg|a3c)})
end
end
+ describe '#filter!' do
+ it 'replaces the passed regexps in the list of filters that determine the stored paths' do
+ subject.filter!(%r{\.(?:jpe?g|gif|png)}, %r{\.(?:mp3|ogg|a3c)})
+ subject.filtering_patterns.should =~ [%r{\.(?:mp3|ogg|a3c)}, %r{\.(?:jpe?g|gif|png)}]
+ end
+ end
+
describe '#ignored?' do
before { subject.stub(:relative_to_base) { |path| path } }
@@ -84,13 +84,27 @@
end
end
+ describe '#ignore!'do
+ it 'delegates the work to the directory record' do
+ subject.directory_record.should_receive(:ignore!).with 'some_directory'
+ subject.ignore! 'some_directory'
+ end
+ end
+
describe '#filter' do
it 'delegates the work to the directory record' do
subject.directory_record.should_receive(:filter).with /\.txt$/
subject.filter /\.txt$/
end
end
+ describe '#filter!' do
+ it 'delegates the work to the directory record' do
+ subject.directory_record.should_receive(:filter!).with /\.txt$/
+ subject.filter! /\.txt$/
+ end
+ end
+
describe '#on_change' do
let(:directories) { %w{dir1 dir2 dir3} }
@@ -80,7 +80,7 @@
end
end
- describe '#ignore'do
+ describe '#ignore' do
it 'delegates the work to each directory record' do
subject.directories_records.each do |r|
r.should_receive(:ignore).with 'some_directory'
@@ -89,6 +89,15 @@
end
end
+ describe '#ignore!' do
+ it 'delegates the work to each directory record' do
+ subject.directories_records.each do |r|
+ r.should_receive(:ignore!).with 'some_directory'
+ end
+ subject.ignore! 'some_directory'
+ end
+ end
+
describe '#filter' do
it 'delegates the work to each directory record' do
subject.directories_records.each do |r|
@@ -98,6 +107,15 @@
end
end
+ describe '#filter!' do
+ it 'delegates the work to each directory record' do
+ subject.directories_records.each do |r|
+ r.should_receive(:filter!).with /\.txt$/
+ end
+ subject.filter! /\.txt$/
+ end
+ end
+
describe '#on_change' do
let(:directories) { %w{dir1 dir2 dir3} }
let(:changes) { {:modified => [], :added => [], :removed => []} }
@@ -81,18 +81,30 @@
end
end
- describe '#ignore'do
+ describe '#ignore' do
it 'returns the same listener to allow chaining' do
subject.ignore('some_directory').should equal subject
end
end
+ describe '#ignore!' do
+ it 'returns the same listener to allow chaining' do
+ subject.ignore!('some_directory').should equal subject
+ end
+ end
+
describe '#filter' do
it 'returns the same listener to allow chaining' do
subject.filter(/\.txt$/).should equal subject
end
end
+ describe '#filter!' do
+ it 'returns the same listener to allow chaining' do
+ subject.filter!(/\.txt$/).should equal subject
+ end
+ end
+
describe '#latency' do
it 'sets the latency to @adapter_options' do
subject.latency(0.7)