Merge pull request #130 from ianwhite/master
Adds ignore_paths option to DSL [#104] [#129]
This commit is contained in:
commit
0d3acdf947
@ -255,10 +255,13 @@ Optional:
|
||||
|
||||
* The `#watch` method allows you to define which files are supervised by this guard. An optional block can be added to overwrite the paths sent to the guard's `#run_on_change` method or to launch any arbitrary command.
|
||||
* The `#group` method allows you to group several guards together. Groups to be run can be specified with the Guard DSL option `--group` (or `-g`). This comes in handy especially when you have a huge Guardfile and want to focus your development on a certain part. Guards that don't belong to a group are considered global and are always run.
|
||||
* The `#ignore_paths` method allows you to ignore top level directories altogether. This comes is handy when you have large amounts of non-source data in you project. By default .bundle, .git, log, tmp, and vendor are ignored. Currently it is only possible to ignore the immediate descendants of the watched directory.
|
||||
|
||||
Example:
|
||||
|
||||
``` ruby
|
||||
ignore_paths 'foo', 'bar'
|
||||
|
||||
group 'backend' do
|
||||
guard 'bundler' do
|
||||
watch('Gemfile')
|
||||
|
@ -134,5 +134,9 @@ module Guard
|
||||
@watchers << ::Guard::Watcher.new(pattern, action)
|
||||
end
|
||||
|
||||
def ignore_paths(*paths)
|
||||
UI.info "Ignoring paths: #{paths.join(', ')}"
|
||||
::Guard.listener.ignore_paths.push(*paths)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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,8 @@ module Guard
|
||||
@directory = directory.to_s
|
||||
@sha1_checksums_hash = {}
|
||||
@relativize_paths = options.fetch(:relativize_paths, true)
|
||||
@ignore_paths = DefaultIgnorePaths
|
||||
@ignore_paths |= options[:ignore_paths] if options[:ignore_paths]
|
||||
update_last_event
|
||||
end
|
||||
|
||||
@ -78,12 +81,17 @@ module Guard
|
||||
!!@relativize_paths
|
||||
end
|
||||
|
||||
# return children of the passed dirs that are not in the ignore_paths list
|
||||
def exclude_ignored_paths(dirs, ignore_paths = self.ignore_paths)
|
||||
Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path|
|
||||
ignore_paths.include?(File.basename(path))
|
||||
end
|
||||
end
|
||||
|
||||
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(dirs)
|
||||
|
||||
if options[:all]
|
||||
paths.inject([]) do |array, path|
|
||||
|
@ -215,6 +215,18 @@ describe Guard::Dsl do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ignore_paths" do
|
||||
disable_user_config
|
||||
|
||||
it "adds the paths to the listener's ignore_paths" do
|
||||
::Guard.stub!(:listener).and_return(mock('Listener'))
|
||||
::Guard.listener.should_receive(:ignore_paths).and_return(ignore_paths = ['faz'])
|
||||
|
||||
subject.evaluate_guardfile(:guardfile_contents => "ignore_paths 'foo', 'bar'")
|
||||
ignore_paths.should == ['faz', 'foo', 'bar']
|
||||
end
|
||||
end
|
||||
|
||||
describe "#group" do
|
||||
disable_user_config
|
||||
|
||||
|
@ -161,4 +161,31 @@ describe Guard::Listener do
|
||||
|
||||
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 added to via :ignore_paths option" do
|
||||
listener = subject.new 'path', :ignore_paths => ['foo', 'bar']
|
||||
listener.ignore_paths.should include('foo', 'bar')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#exclude_ignored_paths [<dirs>]" do
|
||||
let(:ignore_paths) { nil }
|
||||
subject { described_class.new(@fixture_path, {:ignore_paths => ignore_paths}) }
|
||||
|
||||
it "returns children of <dirs>" do
|
||||
subject.exclude_ignored_paths(["spec/fixtures"]).should =~ ["spec/fixtures/.dotfile", "spec/fixtures/folder1", "spec/fixtures/Guardfile"]
|
||||
end
|
||||
|
||||
describe "when ignore_paths set to some of <dirs> children" do
|
||||
let(:ignore_paths) { ['Guardfile', '.dotfile'] }
|
||||
|
||||
it "excludes the ignored paths" do
|
||||
subject.exclude_ignored_paths(["spec/fixtures"]).should =~ ["spec/fixtures/folder1"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user