Merge branch hook of github.com:guard/guard into hook
This commit is contained in:
commit
d798bf05e2
@ -1,13 +1,23 @@
|
|||||||
|
== 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)
|
== 0.3.1 (Avril 14, 2011)
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
- Added a command line option (-n false) to disable notifications (growl/libnotify)
|
- Added a command line option (-n false) to disable notifications (growl/libnotify)
|
||||||
|
|
||||||
Bugs fixes:
|
Bugs fixes:
|
||||||
- Return unique filenames from Linux listener (Marian Schubert)
|
- Return unique filenames from Linux listener (Marian Schubert)
|
||||||
- Guard.get_guard_class return wrong class when loaded nested class. (koshigoe)
|
- 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 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)
|
- Fixed an invalid ANSI escape code in UI.reset_line (@gix)
|
||||||
|
|
||||||
== 0.3.0 (Jan 19, 2011)
|
== 0.3.0 (Jan 19, 2011)
|
||||||
|
|
||||||
|
9
Gemfile
9
Gemfile
@ -4,11 +4,10 @@ gemspec
|
|||||||
|
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
|
|
||||||
if Config::CONFIG['target_os'] =~ /darwin/i
|
if Config::CONFIG['host_os'] =~ /darwin/i
|
||||||
gem 'rb-fsevent', '>= 0.3.9'
|
gem 'rb-fsevent', '>= 0.3.9'
|
||||||
gem 'growl', '~> 1.0.3'
|
gem 'growl', '~> 1.0'
|
||||||
end
|
elsif Config::CONFIG['host_os'] =~ /linux/i
|
||||||
if Config::CONFIG['target_os'] =~ /linux/i
|
|
||||||
gem 'rb-inotify', '>= 0.5.1'
|
gem 'rb-inotify', '>= 0.5.1'
|
||||||
gem 'libnotify', '~> 0.1.3'
|
gem 'libnotify', '~> 0.1'
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
ENV["GUARD_ENV"] = 'development'
|
||||||
|
|
||||||
guard('rspec', :cli => '-f doc', :version => 2) do
|
guard('rspec', :cli => '-f doc', :version => 2) do
|
||||||
watch(%r{^spec/(.*)_spec\.rb})
|
watch(%r{^spec/(.*)_spec\.rb})
|
||||||
watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||||
watch('spec/spec_helper.rb') { "spec" }
|
watch('spec/spec_helper.rb') { "spec" }
|
||||||
end
|
end
|
||||||
|
269
README.markdown
Normal file
269
README.markdown
Normal file
@ -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 <tt>test</tt> 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 <tt>--group</tt> (or <tt>-g</tt>) 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:
|
||||||
|
|
||||||
|
* <tt>Ctrl-C</tt> - Calls each guard's <tt>stop</tt> method, in the same order they are declared in the Guardfile, and then quits Guard itself.
|
||||||
|
* <tt>Ctrl-\\</tt> - Calls each guard's <tt>run_all</tt> method, in the same order they are declared in the Guardfile.
|
||||||
|
* <tt>Ctrl-Z</tt> - Calls each guard's <tt>reload</tt> 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 <tt>test</tt> group):
|
||||||
|
|
||||||
|
``` ruby
|
||||||
|
gem '<guard-name>'
|
||||||
|
```
|
||||||
|
|
||||||
|
Insert default guard's definition to your Guardfile by running this command:
|
||||||
|
|
||||||
|
$ guard init <guard-name>
|
||||||
|
|
||||||
|
You are good to go!
|
||||||
|
|
||||||
|
Guardfile DSL
|
||||||
|
-------------
|
||||||
|
|
||||||
|
The Guardfile DSL consists of just three simple methods: <tt>guard</tt>, <tt>watch</tt> & <tt>group</tt>.
|
||||||
|
|
||||||
|
Required:
|
||||||
|
* The <tt>guard</tt> method allows you to add a guard with an optional hash of options.
|
||||||
|
* The <tt>watch</tt> 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 <tt>run_on_change</tt> guard method or to launch any arbitrary command.
|
||||||
|
|
||||||
|
Optional:
|
||||||
|
* The <tt>group</tt> method allows you to group several guards together. Groups to be run can be specified with the Guard DSL option <tt>--group</tt> (or <tt>-g</tt>). 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 (<tt>bundle gem</tt> if you use Bundler) with this basic structure:
|
||||||
|
|
||||||
|
lib/
|
||||||
|
guard/
|
||||||
|
guard-name/
|
||||||
|
templates/
|
||||||
|
Guardfile (needed for guard init <guard-name>)
|
||||||
|
guard-name.rb
|
||||||
|
|
||||||
|
<tt>Guard::GuardName</tt> (in <tt>lib/guard/guard-name.rb</tt>) must inherit from <tt>Guard::Guard</tt> and should overwrite at least one of the five basic <tt>Guard::Guard</tt> 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)
|
228
README.rdoc
228
README.rdoc
@ -1,228 +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 <tt>test</tt> 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 <tt>--group</tt> (or <tt>-g</tt>) 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:
|
|
||||||
|
|
||||||
- <tt>Ctrl-C</tt> - Calls each guard's <tt>stop</tt> method, in the same order they are declared in the Guardfile, and then quits Guard itself.
|
|
||||||
- <tt>Ctrl-\\</tt> - Calls each guard's <tt>run_all</tt> method, in the same order they are declared in the Guardfile.
|
|
||||||
- <tt>Ctrl-Z</tt> - Calls each guard's <tt>reload</tt> 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 <tt>test</tt> group):
|
|
||||||
|
|
||||||
gem '<guard-name>'
|
|
||||||
|
|
||||||
Insert default guard's definition to your Guardfile by running this command:
|
|
||||||
|
|
||||||
$ guard init <guard-name>
|
|
||||||
|
|
||||||
You are good to go!
|
|
||||||
|
|
||||||
== Guardfile DSL
|
|
||||||
|
|
||||||
The Guardfile DSL consists of just three simple methods: <tt>guard</tt>, <tt>watch</tt> & <tt>group</tt>.
|
|
||||||
|
|
||||||
Required:
|
|
||||||
- The <tt>guard</tt> method allows you to add a guard with an optional hash of options.
|
|
||||||
- The <tt>watch</tt> 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 <tt>run_on_change</tt> guard method or to launch any arbitrary command.
|
|
||||||
|
|
||||||
Optional:
|
|
||||||
- The <tt>group</tt> method allows you to group several guards together. Groups to be run can be specified with the Guard DSL option <tt>--group</tt> (or <tt>-g</tt>). 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 (<tt>bundle gem</tt> if you use Bundler) with this basic structure:
|
|
||||||
|
|
||||||
lib/
|
|
||||||
guard/
|
|
||||||
guard-name/
|
|
||||||
templates/
|
|
||||||
Guardfile (needed for guard init <guard-name>)
|
|
||||||
guard-name.rb
|
|
||||||
|
|
||||||
<tt>Guard::GuardName</tt> (in <tt>lib/guard/guard-name.rb</tt>) must inherit from <tt>Guard::Guard</tt> and should overwrite at least one of the five basic <tt>Guard::Guard</tt> 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.
|
|
||||||
|
|
||||||
== 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]
|
|
6
Rakefile
6
Rakefile
@ -8,14 +8,14 @@ task :default => :spec
|
|||||||
namespace(:spec) do
|
namespace(:spec) do
|
||||||
desc "Run all specs on multiple ruby versions (requires rvm)"
|
desc "Run all specs on multiple ruby versions (requires rvm)"
|
||||||
task(:portability) do
|
task(:portability) do
|
||||||
%w[1.8.6 1.8.7 1.9.2].each do |version|
|
%w[1.8.6 1.8.7 1.9.2 ree].each do |version|
|
||||||
system <<-BASH
|
system <<-BASH
|
||||||
bash -c 'source ~/.rvm/scripts/rvm;
|
bash -c 'source ~/.rvm/scripts/rvm;
|
||||||
rvm #{version};
|
rvm #{version};
|
||||||
echo "--------- version #{version} ----------\n";
|
echo "--------- version #{version} ----------\n";
|
||||||
bundle install;
|
bundle install;
|
||||||
rake spec'
|
rake spec;'
|
||||||
BASH
|
BASH
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
s.add_dependency 'thor', '~> 0.14.6'
|
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.executable = 'guard'
|
||||||
s.require_path = 'lib'
|
s.require_path = 'lib'
|
||||||
end
|
end
|
15
lib/guard.rb
15
lib/guard.rb
@ -1,5 +1,3 @@
|
|||||||
require 'bundler'
|
|
||||||
|
|
||||||
module Guard
|
module Guard
|
||||||
|
|
||||||
autoload :UI, 'guard/ui'
|
autoload :UI, 'guard/ui'
|
||||||
@ -52,8 +50,8 @@ module Guard
|
|||||||
# Reparse the whole directory to catch new files modified during the guards run
|
# Reparse the whole directory to catch new files modified during the guards run
|
||||||
new_modified_files = listener.modified_files([Dir.pwd + '/'], :all => true)
|
new_modified_files = listener.modified_files([Dir.pwd + '/'], :all => true)
|
||||||
listener.update_last_event
|
listener.update_last_event
|
||||||
unless new_modified_files.empty?
|
if !new_modified_files.empty? && Watcher.match_files?(guards, new_modified_files)
|
||||||
run { run_on_change_for_all_guards(new_modified_files) } if Watcher.match_files?(guards, files)
|
run { run_on_change_for_all_guards(new_modified_files) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -89,10 +87,15 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_guard_class(name)
|
def get_guard_class(name)
|
||||||
require "guard/#{name.downcase}"
|
try_to_load_gem name
|
||||||
self.const_get(self.constants.find{|klass_name| klass_name.to_s.downcase == name.downcase })
|
self.const_get(self.constants.find{|klass_name| klass_name.to_s.downcase == name.downcase })
|
||||||
|
rescue TypeError
|
||||||
|
UI.error "Could not find load find gem 'guard-#{name}' or find class Guard::#{name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def try_to_load_gem(name)
|
||||||
|
require "guard/#{name.downcase}"
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
UI.error "Could not find gem 'guard-#{name}', please add it in your Gemfile."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def locate_guard(name)
|
def locate_guard(name)
|
||||||
|
@ -38,4 +38,4 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -43,11 +43,7 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def callback(*args, &listener)
|
def callback(*args, &listener)
|
||||||
listener, events = if args.size > 1
|
listener, events = args.size > 1 ? args : [listener, args[0]]
|
||||||
args
|
|
||||||
else
|
|
||||||
[listener, args[0]]
|
|
||||||
end
|
|
||||||
@callbacks << { :events => events, :listener => listener }
|
@callbacks << { :events => events, :listener => listener }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,4 +54,4 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,32 @@
|
|||||||
module Guard
|
module Guard
|
||||||
module Hook
|
module Hook
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.send :include, InstanceMethods
|
base.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
# When passed a sybmol, #hook will generate a hook name
|
# When +event+ is a Symbol, #hook will generate a hook name
|
||||||
# from the symbol and calling method name. When passed
|
# by concatenating the method name from where #hook is called
|
||||||
# a string, #hook will turn the string into a symbol
|
# with the given Symbol.
|
||||||
# directly.
|
# Example:
|
||||||
|
# def run_all
|
||||||
|
# hook :foo
|
||||||
|
# end
|
||||||
|
# Here, when #run_all is called, #hook will notify callbacks
|
||||||
|
# registered for the "run_all_foo" event.
|
||||||
|
#
|
||||||
|
# When +event+ is a String, #hook will directly turn the String
|
||||||
|
# into a Symbol.
|
||||||
|
# Example:
|
||||||
|
# def run_all
|
||||||
|
# hook "foo_bar"
|
||||||
|
# end
|
||||||
|
# Here, when #run_all is called, #hook will notify callbacks
|
||||||
|
# registered for the "foo_bar" event.
|
||||||
|
#
|
||||||
|
# +args+ parameter is passed as is to the callbacks registered
|
||||||
|
# for the given event.
|
||||||
def hook(event, *args)
|
def hook(event, *args)
|
||||||
hook_name = if event.is_a? Symbol
|
hook_name = if event.is_a? Symbol
|
||||||
calling_method = caller[0][/`([^']*)'/, 1]
|
calling_method = caller[0][/`([^']*)'/, 1]
|
||||||
@ -51,5 +69,6 @@ module Guard
|
|||||||
@callbacks = nil
|
@callbacks = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Guard
|
module Guard
|
||||||
module Interactor
|
module Interactor
|
||||||
|
|
||||||
def self.init_signal_traps
|
def self.init_signal_traps
|
||||||
# Run all (Ctrl-\)
|
# Run all (Ctrl-\)
|
||||||
Signal.trap('QUIT') do
|
Signal.trap('QUIT') do
|
||||||
@ -8,7 +8,7 @@ module Guard
|
|||||||
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) }
|
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stop (Ctrl-C)
|
# Stop (Ctrl-C)
|
||||||
Signal.trap('INT') do
|
Signal.trap('INT') do
|
||||||
UI.info "Bye bye...", :reset => true
|
UI.info "Bye bye...", :reset => true
|
||||||
@ -16,7 +16,7 @@ module Guard
|
|||||||
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) }
|
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) }
|
||||||
abort("\n")
|
abort("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reload (Ctrl-Z)
|
# Reload (Ctrl-Z)
|
||||||
Signal.trap('TSTP') do
|
Signal.trap('TSTP') do
|
||||||
::Guard.run do
|
::Guard.run do
|
||||||
@ -24,6 +24,6 @@ module Guard
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -121,4 +121,4 @@ end
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
@ -63,4 +63,4 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,21 +2,21 @@ module Guard
|
|||||||
module UI
|
module UI
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def info(message, options = {})
|
def info(message, options={})
|
||||||
unless ENV["GUARD_ENV"] == "test"
|
unless ENV["GUARD_ENV"] == "test"
|
||||||
reset_line if options[:reset]
|
reset_line if options[:reset]
|
||||||
puts reset_color(message) if message != ''
|
puts reset_color(message) if message != ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def error(message, options = {})
|
def error(message, options={})
|
||||||
unless ENV["GUARD_ENV"] == "test"
|
unless ENV["GUARD_ENV"] == "test"
|
||||||
reset_line if options[:reset]
|
reset_line if options[:reset]
|
||||||
puts "ERROR: #{message}"
|
puts "ERROR: #{message}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def debug(message, options = {})
|
def debug(message, options={})
|
||||||
unless ENV["GUARD_ENV"] == "test"
|
unless ENV["GUARD_ENV"] == "test"
|
||||||
reset_line if options[:reset]
|
reset_line if options[:reset]
|
||||||
puts "DEBUG: #{message}" if ::Guard.options && ::Guard.options[:debug]
|
puts "DEBUG: #{message}" if ::Guard.options && ::Guard.options[:debug]
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
module Guard
|
module Guard
|
||||||
VERSION = "0.3.1"
|
VERSION = "0.3.4"
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
module Guard
|
module Guard
|
||||||
class Watcher
|
class Watcher
|
||||||
attr_accessor :pattern, :action
|
attr_accessor :pattern, :action
|
||||||
|
|
||||||
def initialize(pattern, action = nil)
|
def initialize(pattern, action = nil)
|
||||||
@pattern, @action = pattern, action
|
@pattern, @action = pattern, action
|
||||||
@@warning_printed ||= false
|
@@warning_printed ||= false
|
||||||
|
|
||||||
# deprecation warning
|
# deprecation warning
|
||||||
if @pattern.is_a?(String) && @pattern =~ /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/
|
if @pattern.is_a?(String) && @pattern =~ /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/
|
||||||
unless @@warning_printed
|
unless @@warning_printed
|
||||||
@ -17,7 +17,7 @@ module Guard
|
|||||||
@pattern = Regexp.new(@pattern)
|
@pattern = Regexp.new(@pattern)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.match_files(guard, files)
|
def self.match_files(guard, files)
|
||||||
guard.watchers.inject([]) do |paths, watcher|
|
guard.watchers.inject([]) do |paths, watcher|
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
@ -33,7 +33,7 @@ module Guard
|
|||||||
paths.flatten.map { |p| p.to_s }
|
paths.flatten.map { |p| p.to_s }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.match_files?(guards, files)
|
def self.match_files?(guards, files)
|
||||||
guards.any? do |guard|
|
guards.any? do |guard|
|
||||||
guard.watchers.any? do |watcher|
|
guard.watchers.any? do |watcher|
|
||||||
@ -41,7 +41,7 @@ module Guard
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_file?(file)
|
def match_file?(file)
|
||||||
if @pattern.is_a?(Regexp)
|
if @pattern.is_a?(Regexp)
|
||||||
file.match(@pattern)
|
file.match(@pattern)
|
||||||
@ -49,7 +49,7 @@ module Guard
|
|||||||
file == @pattern ? [file] : nil
|
file == @pattern ? [file] : nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def call_action(matches)
|
def call_action(matches)
|
||||||
begin
|
begin
|
||||||
@action.arity > 0 ? @action.call(matches) : @action.call
|
@action.arity > 0 ? @action.call(matches) : @action.call
|
||||||
@ -57,6 +57,6 @@ module Guard
|
|||||||
UI.error "Problem with watch action!"
|
UI.error "Problem with watch action!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
require 'guard/guard'
|
||||||
|
|
||||||
describe Guard::Dsl do
|
describe Guard::Dsl do
|
||||||
subject { Guard::Dsl }
|
subject { Guard::Dsl }
|
||||||
|
|
||||||
|
class Guard::Dummy < Guard::Guard; end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
::Guard.stub!(:add_guard)
|
::Guard.stub!(:add_guard)
|
||||||
end
|
end
|
||||||
@ -114,20 +117,23 @@ describe Guard::Dsl do
|
|||||||
describe "#callback" do
|
describe "#callback" do
|
||||||
it "creates callbacks for the guard" do
|
it "creates callbacks for the guard" do
|
||||||
class MyCustomCallback
|
class MyCustomCallback
|
||||||
|
def self.call(guard_class, event, args)
|
||||||
|
# do nothing
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mock_guardfile_content("
|
mock_guardfile_content('
|
||||||
guard 'test' do
|
guard :dummy do
|
||||||
callback(:start_end) { 'Guard::Test started!' }
|
callback(:start_end) { |guard_class, event, args| "#{guard_class} executed \'#{event}\' hook with #{args}!" }
|
||||||
callback(MyCustomCallback, [:start_begin, :run_all_begin])
|
callback(MyCustomCallback, [:start_begin, :run_all_begin])
|
||||||
end")
|
end')
|
||||||
|
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, anything, {}) do |name, watchers, callbacks, options|
|
::Guard.should_receive(:add_guard).with(:dummy, anything, anything, {}) do |name, watchers, callbacks, options|
|
||||||
callbacks.should have(2).items
|
callbacks.should have(2).items
|
||||||
callbacks[0][:events].should == :start_end
|
callbacks[0][:events].should == :start_end
|
||||||
callbacks[0][:listener].call.should == proc { 'Guard::Test started!' }.call
|
callbacks[0][:listener].call(Guard::Dummy, :start_end, 'foo').should == "Guard::Dummy executed 'start_end' hook with foo!"
|
||||||
callbacks[1][:events].should == [:start_begin, :run_all_begin]
|
callbacks[1][:events].should == [:start_begin, :run_all_begin]
|
||||||
callbacks[1][:listener].should == MyCustomCallback
|
callbacks[1][:listener].should == MyCustomCallback
|
||||||
end
|
end
|
||||||
subject.evaluate_guardfile
|
subject.evaluate_guardfile
|
||||||
end
|
end
|
||||||
|
@ -19,9 +19,8 @@ describe Guard::Notifier do
|
|||||||
)
|
)
|
||||||
subject.notify 'great', :title => 'Guard'
|
subject.notify 'great', :title => 'Guard'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if linux?
|
elsif linux?
|
||||||
require 'libnotify'
|
require 'libnotify'
|
||||||
it "uses Libnotify on Linux" do
|
it "uses Libnotify on Linux" do
|
||||||
Libnotify.should_receive(:show).with(
|
Libnotify.should_receive(:show).with(
|
||||||
@ -42,9 +41,8 @@ describe Guard::Notifier do
|
|||||||
Growl.should_not_receive(:notify)
|
Growl.should_not_receive(:notify)
|
||||||
subject.notify 'great', :title => 'Guard'
|
subject.notify 'great', :title => 'Guard'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if linux?
|
elsif linux?
|
||||||
require 'libnotify'
|
require 'libnotify'
|
||||||
it "does nothing" do
|
it "does nothing" do
|
||||||
Libnotify.should_not_receive(:show)
|
Libnotify.should_not_receive(:show)
|
||||||
|
@ -30,15 +30,30 @@ describe Guard do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe ".get_guard_class" do
|
describe ".get_guard_class" do
|
||||||
it "should return Guard::RSpec" do
|
it "should report an error if the class is not found" do
|
||||||
Guard.get_guard_class('rspec').should == Guard::RSpec
|
::Guard::UI.should_receive(:error)
|
||||||
|
Guard.get_guard_class('notAGuardClass')
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'loaded some nested classes' do
|
context 'loaded some nested classes' do
|
||||||
it "should return Guard::RSpec" do
|
it "should find and return loaded class" do
|
||||||
require 'guard/rspec'
|
Guard.should_receive(:try_to_load_gem) { |className|
|
||||||
Guard::RSpec.class_eval('class NotGuardClass; end')
|
className.should == 'classname'
|
||||||
Guard.get_guard_class('rspec').should == Guard::RSpec
|
class Guard::Classname
|
||||||
|
end
|
||||||
|
}
|
||||||
|
Guard.get_guard_class('classname').should == Guard::Classname
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'loaded some inline classes ' do
|
||||||
|
it 'should return inline class' do
|
||||||
|
module Guard
|
||||||
|
class Inline < Guard
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Guard.get_guard_class('inline').should == Guard::Inline
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user