diff --git a/README.md b/README.md index 2b38251..5dfc508 100644 --- a/README.md +++ b/README.md @@ -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') diff --git a/lib/guard/dsl.rb b/lib/guard/dsl.rb index e7d5e6d..c8797b9 100644 --- a/lib/guard/dsl.rb +++ b/lib/guard/dsl.rb @@ -135,6 +135,7 @@ module Guard end def ignore_paths(*paths) + UI.info "Ignoring paths: #{paths.join(', ')}" ::Guard.listener.ignore_paths.push(*paths) end end diff --git a/lib/guard/listener.rb b/lib/guard/listener.rb index d9c6bc5..3c02b41 100644 --- a/lib/guard/listener.rb +++ b/lib/guard/listener.rb @@ -80,7 +80,8 @@ module Guard def relativize_paths? !!@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))