From 38c371272d2aed89d3fc2b7f3150e8a4231606d9 Mon Sep 17 00:00:00 2001 From: Jeff Sacks Date: Mon, 25 Apr 2011 09:18:59 -0500 Subject: [PATCH 01/22] fixing require bug; updating documentation and version --- README.rdoc | 18 +++++++++++++++++- lib/guard.rb | 2 +- lib/guard/version.rb | 4 ++-- spec/guard_spec.rb | 4 ++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.rdoc b/README.rdoc index dfeee74..07f3b59 100644 --- a/README.rdoc +++ b/README.rdoc @@ -215,6 +215,22 @@ Creating a new guard is very easy, just create a new gem (bundle gem if Please take a look at the existing guards' source code (see the list above) for more concrete example. +Alternatively, a new guard can be added inline to a Guardfile with this basic structure: + + require 'guard/guard' + + module ::Guard + class Example < ::Guard::Guard + def run_all + true + end + + def run_on_change(paths) + true + end + end + end + == Development - Source hosted at {GitHub}[https://github.com/guard/guard]. @@ -225,4 +241,4 @@ you make. == Authors -{Thibaud Guillaume-Gentil}[https://github.com/thibaudgg] \ No newline at end of file +{Thibaud Guillaume-Gentil}[https://github.com/thibaudgg] diff --git a/lib/guard.rb b/lib/guard.rb index df2109b..4d9aa2c 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -90,7 +90,7 @@ module Guard end def try_to_load_gem(name) - Kernel.require "guard/#{name.downcase}" + require "guard/#{name.downcase}" rescue LoadError end diff --git a/lib/guard/version.rb b/lib/guard/version.rb index 71fc9ba..1db0eec 100644 --- a/lib/guard/version.rb +++ b/lib/guard/version.rb @@ -1,3 +1,3 @@ module Guard - VERSION = "0.3.3" -end \ No newline at end of file + VERSION = "0.3.4" +end diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index 0162c06..7997a18 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -37,8 +37,8 @@ describe Guard do context 'loaded some nested classes' do it "should find and return loaded class" do - Kernel.should_receive(:require) { |file_name| - file_name.should == 'guard/classname' + Guard.should_receive(:try_to_load_gem) { |className| + className.should == 'classname' class Guard::Classname end } From 76df310cada9acf4176bf0fdbe68cab0830f977e Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Mon, 25 Apr 2011 20:44:18 +0200 Subject: [PATCH 02/22] README rdoc => markdown --- README.markdown | 269 ++++++++++++++++++++++++++++++++++++++++++++++++ README.rdoc | 244 ------------------------------------------- guard.gemspec | 2 +- 3 files changed, 270 insertions(+), 245 deletions(-) create mode 100644 README.markdown delete mode 100644 README.rdoc diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..fc56615 --- /dev/null +++ b/README.markdown @@ -0,0 +1,269 @@ +Guard +===== + +Guard is a command line tool that easily handle events on files modifications. + +Features +-------- + +* [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support on Mac OS X 10.5+ (without RubyCocoa!, [rb-fsevent gem, >= 0.3.5](https://rubygems.org/gems/rb-fsevent) required). +* [Inotify](http://en.wikipedia.org/wiki/Inotify) support on Linux ([rb-inotify gem, >= 0.5.1](https://rubygems.org/gems/rb-inotify) required). +* Polling on the other operating systems (help us to support more OS). +* Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected). +* Growl notifications ([growlnotify](http://growl.info/documentation/growlnotify.php) & [growl gem](https://rubygems.org/gems/growl) required). +* Libnotify notifications ([libnotify gem](https://rubygems.org/gems/libnotify) required). +* Tested on Ruby 1.8.6, 1.8.7 & 1.9.2. + +Install +------- + +Install the gem: + + $ gem install guard + +Add it to your Gemfile (inside the test group): + +``` ruby +gem 'guard' +``` + +Generate an empty Guardfile with: + + $ guard init + +Add the guards you need to your Guardfile (see the existing guards below). + +### On Mac OS X + +Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support: + + $ gem install rb-fsevent + +Install the Growl gem if you want notification support: + + $ gem install growl + +And add it to you Gemfile: + +``` ruby +gem 'growl' +``` + +### On Linux + +Install the rb-inotify gem for [inotify](http://en.wikipedia.org/wiki/Inotify) support: + + $ gem install rb-inotify + +Install the Libnotify gem if you want notification support: + + $ gem install libnotify + +And add it to you Gemfile: + +``` ruby +gem 'libnotify' +``` + +Usage +----- + +Just launch Guard inside your Ruby / Rails project with: + + $ guard [start] + +or if you use Bundler, to run the Guard executable specific to your bundle: + + $ bundle exec guard + +Command line options +-------------------- + +Shell can be cleared after each change with: + + $ guard --clear + $ guard -c # shortcut + +Notifications (growl/libnotify) can be disabled with: + + $ guard --notify false + $ guard -n false # shortcut + +The guards to start can be specified by group (see the Guardfile DSL below) specifying the --group (or -g) option: + + $ guard --group group_name another_group_name + $ guard -g group_name another_group_name # shortcut + +Options list is available with: + + $ guard help [TASK] + +Signal handlers +--------------- + +Signal handlers are used to interact with Guard: + +* Ctrl-C - Calls each guard's stop method, in the same order they are declared in the Guardfile, and then quits Guard itself. +* Ctrl-\\ - Calls each guard's run_all method, in the same order they are declared in the Guardfile. +* Ctrl-Z - Calls each guard's reload method, in the same order they are declared in the Guardfile. + +Available Guards +---------------- + +[Available Guards list](https://github.com/guard/guard/wiki/List-of-available-Guards) (on the wiki now) + +### Add a guard to your Guardfile + +Add it to your Gemfile (inside the test group): + +``` ruby +gem '' +``` + +Insert default guard's definition to your Guardfile by running this command: + + $ guard init + +You are good to go! + +Guardfile DSL +------------- + +The Guardfile DSL consists of just three simple methods: guard, watch & group. + +Required: +* The guard method allows you to add a guard with an optional hash of options. +* 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 run_on_change guard method or to launch any arbitrary command. + +Optional: +* 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. + +Example: + +``` ruby +group 'backend' do + guard 'bundler' do + watch('Gemfile') + end + + guard 'rspec', :cli => '--color --format doc' do + # Regexp watch patterns are matched with Regexp#match + watch(%r{^spec/.+_spec\.rb}) + watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch(%r{^spec/models/.+\.rb}) { ["spec/models", "spec/acceptance"] } + watch(%r{^spec/.+\.rb}) { `say hello` } + + # String watch patterns are matched with simple '==' + watch('spec/spec_helper.rb') { "spec" } + end +end + +group 'frontend' do + guard 'coffeescript', :output => 'public/javascripts/compiled' do + watch(%r{^app/coffeescripts/.+\.coffee}) + end + + guard 'livereload' do + watch(%r{^app/.+\.(erb|haml)}) + end +end +``` + +Create a new guard +------------------ + +Creating a new guard is very easy, just create a new gem (bundle gem if you use Bundler) with this basic structure: + + lib/ + guard/ + guard-name/ + templates/ + Guardfile (needed for guard init ) + guard-name.rb + +Guard::GuardName (in lib/guard/guard-name.rb) must inherit from Guard::Guard and should overwrite at least one of the five basic Guard::Guard instance methods. Example: + +``` ruby +require 'guard' +require 'guard/guard' + +module Guard + class GuardName < Guard + + def initialize(watchers=[], options={}) + super + # init stuff here, thx! + end + + # ================= + # = Guard methods = + # ================= + + # If one of those methods raise an exception, the Guard::GuardName instance + # will be removed from the active guards. + + # Called once when Guard starts + # Please override initialize method to init stuff + def start + true + end + + # Called on Ctrl-C signal (when Guard quits) + def stop + true + end + + # Called on Ctrl-Z signal + # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/... + def reload + true + end + + # Called on Ctrl-/ signal + # This method should be principally used for long action like running all specs/tests/... + def run_all + true + end + + # Called on file(s) modifications + def run_on_change(paths) + true + end + + end +end +``` + +Please take a look at the existing guards' source code (see the list above) for more concrete example. + +Alternatively, a new guard can be added inline to a Guardfile with this basic structure: + +``` ruby +require 'guard/guard' + +module ::Guard + class Example < ::Guard::Guard + def run_all + true + end + + def run_on_change(paths) + true + end + end +end +``` + +Development +----------- + +* Source hosted at [GitHub](https://github.com/guard/guard). +* Report Issues/Questions/Feature requests on [GitHub Issues](https://github.com/guard/guard/issues). + +Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change +you make. + +Author +------ + +{Thibaud Guillaume-Gentil](https://github.com/thibaudgg] diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index 07f3b59..0000000 --- a/README.rdoc +++ /dev/null @@ -1,244 +0,0 @@ -= Guard - -Guard is a command line tool that easily handle events on files modifications. - -== Features - -- {FSEvent}[http://en.wikipedia.org/wiki/FSEvents] support on Mac OS X 10.5+ (without RubyCocoa!, {rb-fsevent gem, >= 0.3.5}[https://rubygems.org/gems/rb-fsevent] required). -- {Inotify}[http://en.wikipedia.org/wiki/Inotify] support on Linux ({rb-inotify gem, >= 0.5.1}[https://rubygems.org/gems/rb-inotify] required). -- Polling on the other operating systems (help us to support more OS). -- Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected). -- Growl notifications ({growlnotify}[http://growl.info/documentation/growlnotify.php] & {growl gem}[https://rubygems.org/gems/growl] required). -- Libnotify notifications ({libnotify gem}[https://rubygems.org/gems/libnotify] required). -- Tested on Ruby 1.8.6, 1.8.7 & 1.9.2. - -== Install - -Install the gem: - - $ gem install guard - -Add it to your Gemfile (inside the test group): - - gem 'guard' - -Generate an empty Guardfile with: - - $ guard init - -Add the guards you need to your Guardfile (see the existing guards below). - -=== On Mac OS X - -Install the rb-fsevent gem for {FSEvent}[http://en.wikipedia.org/wiki/FSEvents] support: - - $ gem install rb-fsevent - -Install the Growl gem if you want notification support: - - $ gem install growl - -And add it to you Gemfile: - - gem 'growl' - -=== On Linux - -Install the rb-inotify gem for {inotify}[http://en.wikipedia.org/wiki/Inotify] support: - - $ gem install rb-inotify - -Install the Libnotify gem if you want notification support: - - $ gem install libnotify - -And add it to you Gemfile: - - gem 'libnotify' - -== Usage - -Just launch Guard inside your Ruby / Rails project with: - - $ guard [start] - -or if you use Bundler, to run the Guard executable specific to your bundle: - - $ bundle exec guard - -== Command line options - -Shell can be cleared after each change with: - - $ guard --clear - $ guard -c # shortcut - -Notifications (growl/libnotify) can be disabled with: - - $ guard --notify false - $ guard -n false # shortcut - -The guards to start can be specified by group (see the Guardfile DSL below) specifying the --group (or -g) option: - - $ guard --group group_name another_group_name - $ guard -g group_name another_group_name # shortcut - -Options list is available with: - - $ guard help [TASK] - -== Signal handlers - -Signal handlers are used to interact with Guard: - -- Ctrl-C - Calls each guard's stop method, in the same order they are declared in the Guardfile, and then quits Guard itself. -- Ctrl-\\ - Calls each guard's run_all method, in the same order they are declared in the Guardfile. -- Ctrl-Z - Calls each guard's reload method, in the same order they are declared in the Guardfile. - -== Available Guards - -{Available Guards list}[https://github.com/guard/guard/wiki/List-of-available-Guards] (on the wiki now) - -=== Add a guard to your Guardfile - -Add it to your Gemfile (inside the test group): - - gem '' - -Insert default guard's definition to your Guardfile by running this command: - - $ guard init - -You are good to go! - -== Guardfile DSL - -The Guardfile DSL consists of just three simple methods: guard, watch & group. - -Required: -- The guard method allows you to add a guard with an optional hash of options. -- 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 run_on_change guard method or to launch any arbitrary command. - -Optional: -- 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. - -Example: - - group 'backend' do - guard 'bundler' do - watch('Gemfile') - end - - guard 'rspec', :cli => '--color --format doc' do - # Regexp watch patterns are matched with Regexp#match - watch(%r{^spec/.+_spec\.rb}) - watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch(%r{^spec/models/.+\.rb}) { ["spec/models", "spec/acceptance"] } - watch(%r{^spec/.+\.rb}) { `say hello` } - - # String watch patterns are matched with simple '==' - watch('spec/spec_helper.rb') { "spec" } - end - end - - group 'frontend' do - guard 'coffeescript', :output => 'public/javascripts/compiled' do - watch(%r{^app/coffeescripts/.+\.coffee}) - end - - guard 'livereload' do - watch(%r{^app/.+\.(erb|haml)}) - end - end - -== Create a new guard - -Creating a new guard is very easy, just create a new gem (bundle gem if you use Bundler) with this basic structure: - - lib/ - guard/ - guard-name/ - templates/ - Guardfile (needed for guard init ) - guard-name.rb - -Guard::GuardName (in lib/guard/guard-name.rb) must inherit from Guard::Guard and should overwrite at least one of the five basic Guard::Guard instance methods. Example: - - require 'guard' - require 'guard/guard' - - module Guard - class GuardName < Guard - - def initialize(watchers=[], options={}) - super - # init stuff here, thx! - end - - # ================= - # = Guard methods = - # ================= - - # If one of those methods raise an exception, the Guard::GuardName instance - # will be removed from the active guards. - - # Called once when Guard starts - # Please override initialize method to init stuff - def start - true - end - - # Called on Ctrl-C signal (when Guard quits) - def stop - true - end - - # Called on Ctrl-Z signal - # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/... - def reload - true - end - - # Called on Ctrl-/ signal - # This method should be principally used for long action like running all specs/tests/... - def run_all - true - end - - # Called on file(s) modifications - def run_on_change(paths) - true - end - - end - end - -Please take a look at the existing guards' source code (see the list above) for more concrete example. - -Alternatively, a new guard can be added inline to a Guardfile with this basic structure: - - require 'guard/guard' - - module ::Guard - class Example < ::Guard::Guard - def run_all - true - end - - def run_on_change(paths) - true - end - end - end - -== Development - -- Source hosted at {GitHub}[https://github.com/guard/guard]. -- Report Issues/Questions/Feature requests on {GitHub Issues}[https://github.com/guard/guard/issues]. - -Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change -you make. - -== Authors - -{Thibaud Guillaume-Gentil}[https://github.com/thibaudgg] diff --git a/guard.gemspec b/guard.gemspec index 045de79..b24b9bb 100644 --- a/guard.gemspec +++ b/guard.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_dependency 'thor', '~> 0.14.6' - s.files = Dir.glob('{bin,images,lib}/**/*') + %w[LICENSE README.rdoc] + s.files = Dir.glob('{bin,images,lib}/**/*') + %w[LICENSE README.markdown] s.executable = 'guard' s.require_path = 'lib' end \ No newline at end of file From ead039b2f2cfaf94e05fef3fe86e25ff2584e1a4 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Mon, 25 Apr 2011 20:45:48 +0200 Subject: [PATCH 03/22] Fixed README --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index fc56615..edd2dc8 100644 --- a/README.markdown +++ b/README.markdown @@ -266,4 +266,4 @@ you make. Author ------ -{Thibaud Guillaume-Gentil](https://github.com/thibaudgg] +[Thibaud Guillaume-Gentil](https://github.com/thibaudgg) From bb28799240e78a3afaff0d34ca68d1d826d3a4ff Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 29 Apr 2011 08:25:57 +0200 Subject: [PATCH 04/22] Removed useless Bundler requirement. Fixes #41 --- lib/guard.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/guard.rb b/lib/guard.rb index 4d9aa2c..b5f1865 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -1,5 +1,3 @@ -require 'bundler' - module Guard autoload :UI, 'guard/ui' From de42d0d08a504cde108193c7710c77bd99c46b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Sat, 30 Apr 2011 01:39:40 +0200 Subject: [PATCH 05/22] Convert CHANGELOG from RDOC to Markdown and cleaned it! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- CHANGELOG.markdown | 90 ++++++++++++++++++++++++++++++++++++++++++++++ CHANGELOG.rdoc | 77 --------------------------------------- README.markdown | 2 ++ 3 files changed, 92 insertions(+), 77 deletions(-) create mode 100644 CHANGELOG.markdown delete mode 100644 CHANGELOG.rdoc diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown new file mode 100644 index 0000000..b8753e2 --- /dev/null +++ b/CHANGELOG.markdown @@ -0,0 +1,90 @@ +### Bugs fixes: + +- Issue #41: Removed useless Bundler requirement. ([@thibaudgg](https://github.com/thibaudgg)) + +### New features: + +- Changed CHANGELOG from RDOC to Markdown and cleaned it! Let's celebrate! ([@rymai](https://github.com/rymai)) +- Changed README from RDOC to Markdown! Let's celebrate! ([@thibaudgg](https://github.com/thibaudgg)) +- Issue #48: Adding support for inline Guard classes rather than requiring a gem. ([@jrsacks](https://github.com/jrsacks)) + + +## 0.3.3 - April 18, 2011 + +### Bugs fixes: + +- Fixed `new_modified_files` rerun conditions on `Guard.run_on_change_for_all_guards`. ([@thibaudgg](https://github.com/thibaudgg)) + + +## 0.3.2 - April 17, 2011 + +### Bugs fixes: + +- Pull request #43: Fixed `guard init` command. ([@brainopia](https://github.com/brainopia)) + + +## 0.3.1 - April 14, 2011 + +### Bugs fixes: + +- Return unique filenames from Linux listener. (Marian Schubert) +- `Guard.get_guard_class` return wrong class when loaded nested class. ([@koshigoe](https://github.com/koshigoe)) +- Issue #35: Fixed open-gem/gem_open dependency problem by using `gem which` to locate guards gem path. (reported by [@thierryhenrio](https://github.com/thierryhenrio), fixed by [@thibaudgg](https://github.com/thibaudgg)) +- Issue #38 & Pull request #39: Fixed an invalid ANSI escape code in `Guard::UI.reset_line`. ([@gix](https://github.com/gix)) + +### New features: + +- Issue #28: New `-n` command line option to disable notifications (Growl / Libnotify). ([@thibaudgg](https://github.com/thibaudgg)) + + +## 0.3.0 - January 19, 2011 + +### Bugs fixes: + +- Avoid launching run_on_change guards method when no files matched. --clear guard argument is now usable. ([@thibaudgg](https://github.com/thibaudgg)) + +### New features: + +- The whole directory is now watched during `run_on_change` to detect new files modifications. ([@thibaudgg](https://github.com/thibaudgg)) +- New DSL method: `group` allows you to group several guards. ([@netzpirat](https://github.com/netzpirat)) +- New CLI option: `--group group_name` to specify certain groups of guards to start. ([@netzpirat](https://github.com/netzpirat)) +- `watch` patterns are now more strict: strings are matched with `String#==`, `Regexp` are matched with `Regexp#match`. ([@rymai](https://github.com/rymai)) +- A deprecation warning is displayed if your `Guardfile` contains `String` that look like `Regexp` (bad!). ([@rymai](https://github.com/rymai)) +- It's now possible to return an `Enumerable` in the `watch` optional blocks in the `Guardfile`. ([@rymai](https://github.com/rymai)) + +### New specs: + +- Guard::Watcher. ([@rymai](https://github.com/rymai)) +- Pull request #13: Guard::Dsl. ([@oliamb](https://github.com/oliamb)) + + +## 0.2.2 - October 25, 2010 + +### Bugs fixes: + +- Issue #5: avoid creating new copy of `fsevent_watch` every time a file is changed. (reported by [@stouset](https://github.com/stouset), fixed by [@thibaudgg](https://github.com/thibaudgg)) + + +## 0.2.1 - October 24, 2010 + +### Bugs fixes: + +- Pull request #7: Fixes for Linux support. ([@yannlugrin](https://github.com/yannlugrin))) +- Pull request #6: Locate guard now chomp newline in result path. ([@yannlugrin](https://github.com/yannlugrin))) + + +## 0.2.0 - October 21, 2010 + +### Bugs fixes: + +- Issue #2: 1.8.6 compatibility. (reported by [@veged](https://github.com/veged), fixed by [@thibaudgg](https://github.com/thibaudgg)) +- Issue #3: `guard init ` no more need `Gemfile` but `open_gem` is required now. (reported by [@wereHamster](https://github.com/wereHamster), fixed by [@thibaudgg](https://github.com/thibaudgg)) +- Removes Growl & Libnotify dependencies. ([@thibaudgg](https://github.com/thibaudgg)) + + +## 0.2.0.beta.1 - October 17, 2010 + +### New features: + +- Improved listeners support (`rb-fsevent` & `rb-inotify`). ([@thibaudgg](https://github.com/thibaudgg)) +- Added polling listening fallback. ([@thibaudgg](https://github.com/thibaudgg)) \ No newline at end of file diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc deleted file mode 100644 index e22ec01..0000000 --- a/CHANGELOG.rdoc +++ /dev/null @@ -1,77 +0,0 @@ -== 0.3.3 (Avril 18, 2011) - -Bugs fixes: -- Fixed new_modified_files rerun conditions on Guard.run_on_change_for_all_guards - -== 0.3.2 (Avril 17, 2011) - -Bugs fixes: -- Fixed "guard init" command (@brainopia) - -== 0.3.1 (Avril 14, 2011) - -Features: -- Added a command line option (-n false) to disable notifications (growl/libnotify) - -Bugs fixes: -- Return unique filenames from Linux listener (Marian Schubert) -- Guard.get_guard_class return wrong class when loaded nested class. (@koshigoe) -- Fixed open-gem/gem_open dependency problem by using `gem which` to locate guards gem path -- Fixed an invalid ANSI escape code in UI.reset_line (@gix) - -== 0.3.0 (Jan 19, 2011) - -== Jan 19, 2011 [by thibaudgg] - -Features: -- The whole directory are now watched after that run_on_change was launched on all guards to detect new files modifications. - -== Dec 17, 2010 [by netzpirat] - -Features: -- New DSL method: `group` allows you to group several guards. -- New CLI option: `--group group_name` to specify certain groups of guards to start. - -== Dec 16, 2010 [by rymai] - -Features: -- 'watch' patterns are now more strict: Strings are matched with '==', Regexp are matched with Regexp#match. -- A deprecation warning is displayed if your Guardfile contains String that look like Regexp (bad!). - -== Nov 26, 2010 [by rymai] - -Features: -- It's now possible to return an enumerable in the 'watch' optional blocks in the Guardfile. - -Specs: -- Guard::Watcher - -Bugs fixes: -- Avoid launching run_on_change guards method when no files matched. --clear guard argument is now usable. - -== 0.2.2 (Oct 25, 2010) - -Bugs fixes: - -- Avoid creating new copy of fsevent_watch every time a file is changed. (issue #5) - -== 0.2.1 (Oct 24, 2010) - -Bugs fixes: - -- Fixes for Linux support - -== 0.2.0 (Oct 21, 2010) - -Bugs fixes: - -- Fixes for 1.8.6 compatibility (issue #2) -- guard init no more need Gemfile presence but open_gem is required now (issue #3) -- Removes growl & libnotify dependencies - -== 0.2.0.beta.1 (Oct 17, 2010) - -Features: - -- Improved listeners support (rb-fsevent & rb-inotify) -- Added polling listening fallback \ No newline at end of file diff --git a/README.markdown b/README.markdown index edd2dc8..6b4c087 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,8 @@ Guard ===== +![travis-ci](http://travis-ci.org/guard/guard.png) + Guard is a command line tool that easily handle events on files modifications. Features From 8d3ad21cb131455a21b19e422180562a0db3b06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Sat, 30 Apr 2011 01:40:54 +0200 Subject: [PATCH 06/22] Added .travis.yml file --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c8fb0a9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +rvm: + - 1.8.6 + - 1.8.7 + - 1.9.2 + - ree From d12a2368b26de6138d190eb09b1c598f145cacf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Sat, 30 Apr 2011 01:47:11 +0200 Subject: [PATCH 07/22] Added links to issues in CHANGELOG --- CHANGELOG.markdown | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index b8753e2..aca5c94 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,12 +1,12 @@ ### Bugs fixes: -- Issue #41: Removed useless Bundler requirement. ([@thibaudgg](https://github.com/thibaudgg)) +- Issue [#41](https://github.com/guard/guard/issues/41): Removed useless Bundler requirement. ([@thibaudgg](https://github.com/thibaudgg)) ### New features: - Changed CHANGELOG from RDOC to Markdown and cleaned it! Let's celebrate! ([@rymai](https://github.com/rymai)) - Changed README from RDOC to Markdown! Let's celebrate! ([@thibaudgg](https://github.com/thibaudgg)) -- Issue #48: Adding support for inline Guard classes rather than requiring a gem. ([@jrsacks](https://github.com/jrsacks)) +- Issue [#48](https://github.com/guard/guard/issues/48): Adding support for inline Guard classes rather than requiring a gem. ([@jrsacks](https://github.com/jrsacks)) ## 0.3.3 - April 18, 2011 @@ -20,7 +20,7 @@ ### Bugs fixes: -- Pull request #43: Fixed `guard init` command. ([@brainopia](https://github.com/brainopia)) +- Pull request [#43](https://github.com/guard/guard/issues/43): Fixed `guard init` command. ([@brainopia](https://github.com/brainopia)) ## 0.3.1 - April 14, 2011 @@ -29,12 +29,12 @@ - Return unique filenames from Linux listener. (Marian Schubert) - `Guard.get_guard_class` return wrong class when loaded nested class. ([@koshigoe](https://github.com/koshigoe)) -- Issue #35: Fixed open-gem/gem_open dependency problem by using `gem which` to locate guards gem path. (reported by [@thierryhenrio](https://github.com/thierryhenrio), fixed by [@thibaudgg](https://github.com/thibaudgg)) -- Issue #38 & Pull request #39: Fixed an invalid ANSI escape code in `Guard::UI.reset_line`. ([@gix](https://github.com/gix)) +- Issue [#35](https://github.com/guard/guard/issues/35): Fixed open-gem/gem_open dependency problem by using `gem which` to locate guards gem path. (reported by [@thierryhenrio](https://github.com/thierryhenrio), fixed by [@thibaudgg](https://github.com/thibaudgg)) +- Issue [#38](https://github.com/guard/guard/issues/38) & Pull request [#39](https://github.com/guard/guard/issues/39): Fixed an invalid ANSI escape code in `Guard::UI.reset_line`. ([@gix](https://github.com/gix)) ### New features: -- Issue #28: New `-n` command line option to disable notifications (Growl / Libnotify). ([@thibaudgg](https://github.com/thibaudgg)) +- Issue [#28](https://github.com/guard/guard/issues/28): New `-n` command line option to disable notifications (Growl / Libnotify). ([@thibaudgg](https://github.com/thibaudgg)) ## 0.3.0 - January 19, 2011 @@ -46,8 +46,8 @@ ### New features: - The whole directory is now watched during `run_on_change` to detect new files modifications. ([@thibaudgg](https://github.com/thibaudgg)) -- New DSL method: `group` allows you to group several guards. ([@netzpirat](https://github.com/netzpirat)) -- New CLI option: `--group group_name` to specify certain groups of guards to start. ([@netzpirat](https://github.com/netzpirat)) +- Pull request [#26](https://github.com/guard/guard/issues/26): New DSL method: `group` allows you to group several guards. ([@netzpirat](https://github.com/netzpirat)) +- Pull request [#26](https://github.com/guard/guard/issues/26): New CLI option: `--group group_name` to specify certain groups of guards to start. ([@netzpirat](https://github.com/netzpirat)) - `watch` patterns are now more strict: strings are matched with `String#==`, `Regexp` are matched with `Regexp#match`. ([@rymai](https://github.com/rymai)) - A deprecation warning is displayed if your `Guardfile` contains `String` that look like `Regexp` (bad!). ([@rymai](https://github.com/rymai)) - It's now possible to return an `Enumerable` in the `watch` optional blocks in the `Guardfile`. ([@rymai](https://github.com/rymai)) @@ -55,30 +55,30 @@ ### New specs: - Guard::Watcher. ([@rymai](https://github.com/rymai)) -- Pull request #13: Guard::Dsl. ([@oliamb](https://github.com/oliamb)) +- Pull request [#13](https://github.com/guard/guard/issues/13): Guard::Dsl. ([@oliamb](https://github.com/oliamb)) ## 0.2.2 - October 25, 2010 ### Bugs fixes: -- Issue #5: avoid creating new copy of `fsevent_watch` every time a file is changed. (reported by [@stouset](https://github.com/stouset), fixed by [@thibaudgg](https://github.com/thibaudgg)) +- Issue [#5](https://github.com/guard/guard/issues/5): avoid creating new copy of `fsevent_watch` every time a file is changed. (reported by [@stouset](https://github.com/stouset), fixed by [@thibaudgg](https://github.com/thibaudgg)) ## 0.2.1 - October 24, 2010 ### Bugs fixes: -- Pull request #7: Fixes for Linux support. ([@yannlugrin](https://github.com/yannlugrin))) -- Pull request #6: Locate guard now chomp newline in result path. ([@yannlugrin](https://github.com/yannlugrin))) +- Pull request [#7](https://github.com/guard/guard/issues/7): Fixes for Linux support. ([@yannlugrin](https://github.com/yannlugrin))) +- Pull request [#6](https://github.com/guard/guard/issues/6): Locate guard now chomp newline in result path. ([@yannlugrin](https://github.com/yannlugrin))) ## 0.2.0 - October 21, 2010 ### Bugs fixes: -- Issue #2: 1.8.6 compatibility. (reported by [@veged](https://github.com/veged), fixed by [@thibaudgg](https://github.com/thibaudgg)) -- Issue #3: `guard init ` no more need `Gemfile` but `open_gem` is required now. (reported by [@wereHamster](https://github.com/wereHamster), fixed by [@thibaudgg](https://github.com/thibaudgg)) +- Issue [#3](https://github.com/guard/guard/issues/3): `guard init ` no more need `Gemfile` but `open_gem` is required now. (reported by [@wereHamster](https://github.com/wereHamster), fixed by [@thibaudgg](https://github.com/thibaudgg)) +- Issue [#2](https://github.com/guard/guard/issues/2): 1.8.6 compatibility. (reported by [@veged](https://github.com/veged), fixed by [@thibaudgg](https://github.com/thibaudgg)) - Removes Growl & Libnotify dependencies. ([@thibaudgg](https://github.com/thibaudgg)) From cefb87236085e35fd49eb97f6db0dfb51b296a30 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Thu, 5 May 2011 20:14:58 -0300 Subject: [PATCH 08/22] Changed some conditions to positive statement --- lib/guard/listeners/darwin.rb | 2 +- lib/guard/listeners/linux.rb | 4 ++-- lib/guard/listeners/polling.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/guard/listeners/darwin.rb b/lib/guard/listeners/darwin.rb index c6eb055..775a368 100644 --- a/lib/guard/listeners/darwin.rb +++ b/lib/guard/listeners/darwin.rb @@ -25,7 +25,7 @@ module Guard def self.usable? require 'rb-fsevent' - if !defined?(FSEvent::VERSION) || Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.3.9') + unless defined?(FSEvent::VERSION) || Gem::Version.new(FSEvent::VERSION) >= Gem::Version.new('0.3.9') UI.info "Please update rb-fsevent (>= 0.3.9)" false else diff --git a/lib/guard/listeners/linux.rb b/lib/guard/listeners/linux.rb index 6436d59..f7c5668 100644 --- a/lib/guard/listeners/linux.rb +++ b/lib/guard/listeners/linux.rb @@ -32,7 +32,7 @@ module Guard def self.usable? require 'rb-inotify' - if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1') + unless defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) >= Gem::Version.new('0.5.1') UI.info "Please update rb-inotify (>= 0.5.1)" false else @@ -51,7 +51,7 @@ module Guard def watch_change @watch_change = true - while !@stop + until @stop if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency) break if @stop diff --git a/lib/guard/listeners/polling.rb b/lib/guard/listeners/polling.rb index e0dd5ca..bf5a17b 100644 --- a/lib/guard/listeners/polling.rb +++ b/lib/guard/listeners/polling.rb @@ -23,7 +23,7 @@ module Guard private def watch_change - while !@stop + until @stop start = Time.now.to_f files = modified_files([Dir.pwd + '/'], :all => true) update_last_event From ed0b086cc5885018527a7fca5ca82345c03306d6 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Thu, 5 May 2011 20:52:11 -0300 Subject: [PATCH 09/22] Removed the unless with multiple conditions. Changed it back to if --- lib/guard/listeners/darwin.rb | 2 +- lib/guard/listeners/linux.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/guard/listeners/darwin.rb b/lib/guard/listeners/darwin.rb index 775a368..c6eb055 100644 --- a/lib/guard/listeners/darwin.rb +++ b/lib/guard/listeners/darwin.rb @@ -25,7 +25,7 @@ module Guard def self.usable? require 'rb-fsevent' - unless defined?(FSEvent::VERSION) || Gem::Version.new(FSEvent::VERSION) >= Gem::Version.new('0.3.9') + if !defined?(FSEvent::VERSION) || Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.3.9') UI.info "Please update rb-fsevent (>= 0.3.9)" false else diff --git a/lib/guard/listeners/linux.rb b/lib/guard/listeners/linux.rb index f7c5668..2d53b62 100644 --- a/lib/guard/listeners/linux.rb +++ b/lib/guard/listeners/linux.rb @@ -32,7 +32,7 @@ module Guard def self.usable? require 'rb-inotify' - unless defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) >= Gem::Version.new('0.5.1') + if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1') UI.info "Please update rb-inotify (>= 0.5.1)" false else From 5c1e264c391011c520443c575d802cdc8839a544 Mon Sep 17 00:00:00 2001 From: Nick Sieger Date: Fri, 6 May 2011 12:09:00 -0500 Subject: [PATCH 10/22] Fix spec on JRuby that was failing due to different execution order --- lib/guard/notifier.rb | 4 ++++ spec/guard/notifier_spec.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index d250a22..52204e2 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -8,6 +8,10 @@ module Guard @disable = true end + def self.turn_on + @disable = nil + end + def self.notify(message, options = {}) unless @disable || ENV["GUARD_ENV"] == "test" image = options[:image] || :success diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index b12781b..603d05b 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -7,6 +7,7 @@ describe Guard::Notifier do before(:each) do @saved_guard_env = ENV["GUARD_ENV"] ENV["GUARD_ENV"] = 'dont_mute_notify' + subject.turn_on end if mac? From 70c15a7c94b352f26f5c5cdaf1ec1528c0191fc2 Mon Sep 17 00:00:00 2001 From: Nick Sieger Date: Fri, 6 May 2011 12:29:24 -0500 Subject: [PATCH 11/22] Extract code from signal handlers into methods This will allow building other mechanisms to interact with Guard, for example on JRuby, where signal handling tends to be unreliable. --- lib/guard/interactor.rb | 42 ++++++++++++++++++++++------------- spec/guard/interactor_spec.rb | 25 +++++++++++++++++++++ 2 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 spec/guard/interactor_spec.rb diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index f5247eb..9568631 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -1,29 +1,41 @@ module Guard module Interactor - + extend self + + def run_all + ::Guard.run do + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } + end + end + + def stop + UI.info "Bye bye...", :reset => true + ::Guard.listener.stop + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } + abort("\n") + end + + def reload + ::Guard.run do + ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } + end + end + def self.init_signal_traps # Run all (Ctrl-\) Signal.trap('QUIT') do - ::Guard.run do - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) } - end + run_all end - + # Stop (Ctrl-C) Signal.trap('INT') do - UI.info "Bye bye...", :reset => true - ::Guard.listener.stop - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } - abort("\n") + stop end - + # Reload (Ctrl-Z) Signal.trap('TSTP') do - ::Guard.run do - ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) } - end + reload end end - end -end \ No newline at end of file +end diff --git a/spec/guard/interactor_spec.rb b/spec/guard/interactor_spec.rb new file mode 100644 index 0000000..6471f52 --- /dev/null +++ b/spec/guard/interactor_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Guard::Interactor do + subject { Guard::Interactor } + let(:guard) { mock "guard" } + before :each do + Guard.stub!(:guards).and_return([guard]) + Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil)) + end + + it ".run_all should send :run_all to all guards" do + guard.should_receive(:run_all) + subject.run_all + end + + it ".stop should send :stop to all guards" do + guard.should_receive(:stop) + lambda { subject.stop }.should raise_error(SystemExit) + end + + it ".reload should send :reload to all guards" do + guard.should_receive(:reload) + subject.reload + end +end From 869ed2fa28b60f04f90e2d91e514d505911abea9 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 21:14:39 +0200 Subject: [PATCH 12/22] Fixed Interactor spec --- spec/guard/interactor_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/guard/interactor_spec.rb b/spec/guard/interactor_spec.rb index 6471f52..9621831 100644 --- a/spec/guard/interactor_spec.rb +++ b/spec/guard/interactor_spec.rb @@ -3,8 +3,10 @@ require 'spec_helper' describe Guard::Interactor do subject { Guard::Interactor } let(:guard) { mock "guard" } + before :each do Guard.stub!(:guards).and_return([guard]) + Guard.stub!(:options).and_return({}) Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil)) end From f7e9e42dcebf7e81973a59f3f3018c662088e5a3 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 21:15:33 +0200 Subject: [PATCH 13/22] Skipped Darwin/Linux listener specs if rb-fsevent/rb-inotify not available --- spec/guard/listeners/darwin_spec.rb | 2 +- spec/guard/listeners/linux_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/guard/listeners/darwin_spec.rb b/spec/guard/listeners/darwin_spec.rb index 7a562f1..6168f49 100644 --- a/spec/guard/listeners/darwin_spec.rb +++ b/spec/guard/listeners/darwin_spec.rb @@ -10,7 +10,7 @@ describe Guard::Darwin do end end - if mac? + if mac? && Guard::Darwin.usable? it "is usable on 10.6" do subject.should be_usable end diff --git a/spec/guard/listeners/linux_spec.rb b/spec/guard/listeners/linux_spec.rb index ba5d86f..bbdffba 100644 --- a/spec/guard/listeners/linux_spec.rb +++ b/spec/guard/listeners/linux_spec.rb @@ -11,7 +11,7 @@ describe Guard::Linux do end end - if linux? + if linux? && Guard::Linux.usable? it "is usable on linux" do subject.should be_usable end From 2da724f5e9f8071c5c401b957f81a1771b8100ad Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 21:23:30 +0200 Subject: [PATCH 14/22] Fixed Rubygems deprecation messages --- lib/guard.rb | 2 +- spec/guard_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/guard.rb b/lib/guard.rb index b5f1865..23ffd8a 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -93,7 +93,7 @@ module Guard end def locate_guard(name) - Gem.source_index.find_name("guard-#{name}").last.full_gem_path + Gem::Specification.find_by_name("guard-#{name}").full_gem_path rescue UI.error "Could not find 'guard-#{name}' gem path." end diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index 7997a18..c776314 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -111,7 +111,7 @@ describe Guard do describe ".locate_guard" do it "returns the path of the guard gem" do - Guard.locate_guard('rspec').should == Gem.source_index.find_name("guard-rspec").last.full_gem_path + Guard.locate_guard('rspec').should == Gem::Specification.find_by_name("guard-rspec").full_gem_path end end end From 660baf7adcb62349872fa797725a4fb734d73e06 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 21:24:00 +0200 Subject: [PATCH 15/22] Tried to not require rb-inotify (travis-ci issue) --- Gemfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index a7126b6..96997fc 100644 --- a/Gemfile +++ b/Gemfile @@ -5,10 +5,10 @@ gemspec require 'rbconfig' if Config::CONFIG['target_os'] =~ /darwin/i - gem 'rb-fsevent', '>= 0.3.9' - gem 'growl', '~> 1.0.3' + gem 'rb-fsevent', '>= 0.3.9', :require => false + gem 'growl', '~> 1.0.3', :require => false end if Config::CONFIG['target_os'] =~ /linux/i - gem 'rb-inotify', '>= 0.5.1' - gem 'libnotify', '~> 0.1.3' + gem 'rb-inotify', '>= 0.5.1', :require => false + gem 'libnotify', '~> 0.1.3', :require => false end From 296837895ac7536edb859f79cc79db5e71068d09 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 21:27:28 +0200 Subject: [PATCH 16/22] Skipped Guard::Notifier spec if growl/libnotify not installed --- spec/guard/notifier_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 603d05b..652d9ef 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -10,8 +10,7 @@ describe Guard::Notifier do subject.turn_on end - if mac? - require 'growl' + if mac? && Guard::Notifier.growl_installed? it "uses Growl on Mac OS X" do Growl.should_receive(:notify).with("great", :title => "Guard", @@ -22,8 +21,7 @@ describe Guard::Notifier do end end - if linux? - require 'libnotify' + if linux? && Guard::Notifier.libnotify_installed? it "uses Libnotify on Linux" do Libnotify.should_receive(:show).with( :body => "great", From a84e46ab48d30353e9bbf1358be2472c34b0cac5 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 21:29:22 +0200 Subject: [PATCH 17/22] Oups! --- spec/guard/notifier_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 652d9ef..900684d 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -35,16 +35,14 @@ describe Guard::Notifier do describe ".turn_off" do before(:each) { subject.turn_off } - if mac? - require 'growl' + if mac? && Guard::Notifier.growl_installed? it "does nothing" do Growl.should_not_receive(:notify) subject.notify 'great', :title => 'Guard' end end - if linux? - require 'libnotify' + if linux? && Guard::Notifier.libnotify_installed? it "does nothing" do Libnotify.should_not_receive(:show) subject.notify 'great', :title => 'Guard' From 5740548a517ef1574d2f121bcdbfc90d3c1d60af Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 21:51:50 +0200 Subject: [PATCH 18/22] Kept support of Rubygems < 1.8.0 (for now!) --- lib/guard.rb | 6 +++++- spec/guard_spec.rb | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/guard.rb b/lib/guard.rb index 23ffd8a..2e1f869 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -93,7 +93,11 @@ module Guard end def locate_guard(name) - Gem::Specification.find_by_name("guard-#{name}").full_gem_path + if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0') + Gem::Specification.find_by_name("guard-#{name}").full_gem_path + else + Gem.source_index.find_name("guard-#{name}").last.full_gem_path + end rescue UI.error "Could not find 'guard-#{name}' gem path." end diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index c776314..f635a4f 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -111,7 +111,13 @@ describe Guard do describe ".locate_guard" do it "returns the path of the guard gem" do - Guard.locate_guard('rspec').should == Gem::Specification.find_by_name("guard-rspec").full_gem_path + if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0') + gem_location = Gem::Specification.find_by_name("guard-rspec").full_gem_path + else + gem_location = Gem.source_index.find_name("guard-rspec").last.full_gem_path + end + + Guard.locate_guard('rspec').should == gem_location end end end From d7394e426223e0e29085f6a37245f89591fa12db Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 22:10:38 +0200 Subject: [PATCH 19/22] Bye bye 1.8.6 support. --- .travis.yml | 1 - README.markdown | 2 +- Rakefile | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c8fb0a9..36b2ab4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ rvm: - - 1.8.6 - 1.8.7 - 1.9.2 - ree diff --git a/README.markdown b/README.markdown index 6b4c087..d38176c 100644 --- a/README.markdown +++ b/README.markdown @@ -14,7 +14,7 @@ Features * Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected). * Growl notifications ([growlnotify](http://growl.info/documentation/growlnotify.php) & [growl gem](https://rubygems.org/gems/growl) required). * Libnotify notifications ([libnotify gem](https://rubygems.org/gems/libnotify) required). -* Tested on Ruby 1.8.6, 1.8.7 & 1.9.2. +* Tested on Ruby 1.8.7, 1.9.2 && ree. Install ------- diff --git a/Rakefile b/Rakefile index 4541498..289b504 100644 --- a/Rakefile +++ b/Rakefile @@ -8,7 +8,7 @@ task :default => :spec namespace(:spec) do desc "Run all specs on multiple ruby versions (requires rvm)" task(:portability) do - %w[1.8.6 1.8.7 1.9.2].each do |version| + %w[1.8.7 1.9.2 ree].each do |version| system <<-BASH bash -c 'source ~/.rvm/scripts/rvm; rvm #{version}; From 75c1758b223b6e14f800a0c2cdc14257be1361fb Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 22:57:44 +0200 Subject: [PATCH 20/22] Updated Guardfile --- Guardfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Guardfile b/Guardfile index c7303d5..d5c6bd9 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -guard('rspec', :cli => '-f doc', :version => 2) do +guard('rspec', :version => 2) do watch(%r{^spec/(.*)_spec\.rb}) watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } From fa44ef31bc79cc93b86706318a20449fab706c36 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 22:58:18 +0200 Subject: [PATCH 21/22] Moved stop "\n" --- lib/guard/interactor.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index 9568631..4acd9ed 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -9,10 +9,10 @@ module Guard end def stop - UI.info "Bye bye...", :reset => true + UI.info "Bye bye...\n", :reset => true ::Guard.listener.stop ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) } - abort("\n") + abort end def reload From 2f94f9e22f152b5c5cf8d65a7fba4f598250c12b Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Fri, 6 May 2011 23:19:31 +0200 Subject: [PATCH 22/22] Fixed notification option Only print notification "Install message" once Added GUARD_NOTIFY=false env variable support Fixes #28 --- README.markdown | 2 + lib/guard.rb | 3 +- lib/guard/notifier.rb | 48 +++++++++++------------ spec/guard/notifier_spec.rb | 76 +++++++++++++++++++------------------ spec/guard_spec.rb | 12 ++++++ spec/spec_helper.rb | 1 + spec/support/gems_helper.rb | 13 +++++++ 7 files changed, 93 insertions(+), 62 deletions(-) create mode 100644 spec/support/gems_helper.rb diff --git a/README.markdown b/README.markdown index d38176c..1a8d72a 100644 --- a/README.markdown +++ b/README.markdown @@ -91,6 +91,8 @@ Notifications (growl/libnotify) can be disabled with: $ guard --notify false $ guard -n false # shortcut +Notifications can also be disabled by setting a `GUARD_NOTIFY` environment variable to `false` + The guards to start can be specified by group (see the Guardfile DSL below) specifying the --group (or -g) option: $ guard --group group_name another_group_name diff --git a/lib/guard.rb b/lib/guard.rb index 2e1f869..12c35a9 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -16,7 +16,8 @@ module Guard @listener = Listener.select_and_init @guards = [] - Notifier.turn_off unless options[:notify] + options[:notify] = false if ENV["GUARD_NOTIFY"] == 'false' + options[:notify] ? Notifier.turn_on : Notifier.turn_off self end diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index 52204e2..27e92df 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -9,26 +9,32 @@ module Guard end def self.turn_on - @disable = nil + @disable = false + case Config::CONFIG['target_os'] + when /darwin/i + require_growl + when /linux/i + require_libnotify + end end def self.notify(message, options = {}) - unless @disable || ENV["GUARD_ENV"] == "test" + unless @disable image = options[:image] || :success title = options[:title] || "Guard" case Config::CONFIG['target_os'] when /darwin/i - if growl_installed? - Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard" - end + Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard" when /linux/i - if libnotify_installed? - Libnotify.show :body => message, :summary => title, :icon_path => image_path(image) - end + Libnotify.show :body => message, :summary => title, :icon_path => image_path(image) end end end + def self.disabled? + @disable + end + private def self.image_path(image) @@ -46,24 +52,18 @@ module Guard end end - def self.growl_installed? - @installed ||= begin - require 'growl' - true - rescue LoadError - UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile" - false - end + def self.require_growl + require 'growl' + rescue LoadError + @disable = true + UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile" end - def self.libnotify_installed? - @installed ||= begin - require 'libnotify' - true - rescue LoadError - UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile" - false - end + def self.require_libnotify + require 'libnotify' + rescue LoadError + @disable = true + UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile" end end diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 900684d..e09622c 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -4,53 +4,55 @@ describe Guard::Notifier do subject { Guard::Notifier } describe ".notify" do - before(:each) do - @saved_guard_env = ENV["GUARD_ENV"] - ENV["GUARD_ENV"] = 'dont_mute_notify' - subject.turn_on + before(:each) { subject.turn_on } + + if mac? + if growl_installed? + it "uses Growl on Mac OS X" do + Growl.should_receive(:notify).with("great", + :title => "Guard", + :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s, + :name => "Guard" + ) + subject.notify 'great', :title => 'Guard' + end + else + it { should be_disabled } + end end - if mac? && Guard::Notifier.growl_installed? - it "uses Growl on Mac OS X" do - Growl.should_receive(:notify).with("great", - :title => "Guard", - :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s, - :name => "Guard" - ) + if linux? + if libnotify_installed? + it "uses Libnotify on Linux" do + Libnotify.should_receive(:show).with( + :body => "great", + :summary => 'Guard', + :icon_path => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s + ) + subject.notify 'great', :title => 'Guard' + end + else + it { should be_disabled } + end + end + end + + describe ".turn_off" do + if mac? && growl_installed? + it "does nothing" do + Growl.should_not_receive(:notify) subject.notify 'great', :title => 'Guard' end end - if linux? && Guard::Notifier.libnotify_installed? - it "uses Libnotify on Linux" do - Libnotify.should_receive(:show).with( - :body => "great", - :summary => 'Guard', - :icon_path => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s - ) + if linux? && libnotify_installed? + it "does nothing" do + Libnotify.should_not_receive(:show) subject.notify 'great', :title => 'Guard' end end - describe ".turn_off" do - before(:each) { subject.turn_off } - - if mac? && Guard::Notifier.growl_installed? - it "does nothing" do - Growl.should_not_receive(:notify) - subject.notify 'great', :title => 'Guard' - end - end - - if linux? && Guard::Notifier.libnotify_installed? - it "does nothing" do - Libnotify.should_not_receive(:show) - subject.notify 'great', :title => 'Guard' - end - end - end - - after(:each) { ENV["GUARD_ENV"] = @saved_guard_env } + it { should be_disabled } end end diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index f635a4f..bf3faa8 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -23,10 +23,22 @@ describe Guard do ::Guard.listener.should be_kind_of(Guard::Listener) end + it "should turn on by default" do + ::Guard::Notifier.should_receive(:turn_on) + ::Guard.setup(:notify => true) + end + it "should turn off notifier if notify option is false" do ::Guard::Notifier.should_receive(:turn_off) ::Guard.setup(:notify => false) end + + it "should turn off notifier if env[GUARD_NOTIFY] is false" do + ::Guard::Notifier.should_receive(:turn_off) + ENV["GUARD_NOTIFY"] = 'false' + ::Guard.setup(:notify => true) + ENV["GUARD_NOTIFY"] = nil + end end describe ".get_guard_class" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1520849..f69ed16 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,6 +15,7 @@ RSpec.configure do |config| config.run_all_when_everything_filtered = true config.before(:each) do + Guard::Notifier.turn_off @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__)) end diff --git a/spec/support/gems_helper.rb b/spec/support/gems_helper.rb new file mode 100644 index 0000000..2ccf7fe --- /dev/null +++ b/spec/support/gems_helper.rb @@ -0,0 +1,13 @@ +def growl_installed? + require 'growl' + true +rescue LoadError + false +end + +def libnotify_installed? + require 'libnotify' + true +rescue LoadError + false +end \ No newline at end of file