Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:guard/guard

  • Loading branch information...
commit b44a91bfef8c0994e0dc5792d0d5b8360708ef04 2 parents ec7ba3c + 52cf570
@rymai rymai authored
View
3  CHANGELOG.md
@@ -1,4 +1,4 @@
-## Master
+## 0.6.0 - August 13, 2011
### Bugs fixes:
@@ -11,6 +11,7 @@
### Improvements
+- Pull request [#99](https://github.com/guard/guard/pull/99): [OS X] Switch from growl gem to growl_notify gem. ([@johnbintz][])
- Pull request [#115](https://github.com/guard/guard/pull/115): [Linux] Add ':transient => true' to default libnotify options. ([@zonque][])
- Pull request [#95](https://github.com/guard/guard/pull/95): Output system commands and options to be executed when in debug mode. ([@uk-ar][] and [@netzpirat][])
- `Guard::Dsl.revaluate_guardfile` has been renamed to `Guard::Dsl.reevaluate_guardfile`. ([@rymai][])
View
2  Gemfile
@@ -16,7 +16,7 @@ require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.4.0', :require => false
- gem 'growl', '~> 1.0.3', :require => false
+ gem 'growl_notify', :require => false
end
if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.8.5', :require => false
View
49 README.md
@@ -15,7 +15,12 @@ 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.7, 1.9.2 && ree.
+* Tested against Ruby 1.8.7, 1.9.2 and REE.
+
+Screencast
+----------
+
+Ryan Bates made a screencast on Guard, you can view it here: http://railscasts.com/episodes/264-guard
Install
-------
@@ -50,17 +55,17 @@ Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents)
$ gem install rb-fsevent
```
-Install the Growl gem if you want notification support:
+Install the growl_notify gem if you want notification support:
``` bash
-$ gem install growl
+$ gem install growl_notify
```
-And add them to your Gemfile:
+And add it to your Gemfile:
``` ruby
gem 'rb-fsevent'
-gem 'growl'
+gem 'growl_notify'
```
### On Linux
@@ -92,6 +97,12 @@ Install the rb-fchange gem for [Directory Change Notification](http://msdn.micro
$ gem install rb-fchange
```
+Install the win32console gem if you want colors in your terminal:
+
+``` bash
+$ gem install win32console
+```
+
Install the Notifu gem if you want notification support:
``` bash
@@ -125,7 +136,7 @@ Guard will look for a Guardfile in your current directory. If it does not find o
Command line options
--------------------
-### `--clear` option
+### `-c`/`--clear` option
Shell can be cleared after each change:
@@ -134,7 +145,7 @@ $ guard --clear
$ guard -c # shortcut
```
-### `--notify` option
+### `-n`/`--notify` option
Notifications (growl/libnotify) can be disabled:
@@ -145,7 +156,7 @@ $ guard -n f # shortcut
Notifications can also be disabled globally by setting a `GUARD_NOTIFY` environment variable to `false`
-### `--group` option
+### `-g`/`--group` option
Only certain guards groups can be run (see the Guardfile DSL below for creating groups):
@@ -154,7 +165,7 @@ $ guard --group group_name another_group_name
$ guard -g group_name another_group_name # shortcut
```
-### `--debug` option
+### `-d`/`--debug` option
Guard can be run in debug mode:
@@ -163,6 +174,24 @@ $ guard --debug
$ guard -d # shortcut
```
+### `-w`/`--watchdir` option
+
+Guard can watch in any directory (instead of the current directory):
+
+``` bash
+$ guard --watchdir ~/your/fancy/project
+$ guard -w ~/your/fancy/project # shortcut
+```
+
+### `-G`/`--guardfile` option
+
+Guard can use a Guardfile not located in the current directory:
+
+``` bash
+$ guard --guardfile ~/.your_global_guardfile
+$ guard -G ~/.your_global_guardfile # shortcut
+```
+
An exhaustive list of options is available with:
``` bash
@@ -219,7 +248,7 @@ Required:
Optional:
* The `#watch` method allows you to define which files are supervised by this guard. An optional block can be added to overwrite the paths sent to the guard's `#run_on_change` method or to launch any arbitrary command.
-* The `#group` method allows you to group several guards together. Groups to be run can be specified with the Guard DSL option `--group` (or `-g`). This comes in handy especially when you have a huge Guardfile and want to focus your development on a certain part.
+* The `#group` method allows you to group several guards together. Groups to be run can be specified with the Guard DSL option `--group` (or `-g`). This comes in handy especially when you have a huge Guardfile and want to focus your development on a certain part. Guards that don't belong to a group are considered global and are always run.
Example:
View
4 lib/guard/dsl.rb
@@ -14,6 +14,7 @@ def evaluate_guardfile(options = {})
def reevaluate_guardfile
::Guard.guards.clear
+ @@options.delete(:guardfile_contents)
Dsl.evaluate_guardfile(@@options)
msg = "Guardfile has been re-evaluated."
UI.info(msg)
@@ -104,7 +105,8 @@ def home_guardfile_path
end
def group(name, &guard_definition)
- guard_definition.call if guard_definition && (@@options[:group].empty? || @@options[:group].include?(name.to_s))
+ @groups = @@options[:group] || []
+ guard_definition.call if guard_definition && (@groups.empty? || @groups.include?(name.to_s))
end
def guard(name, options = {}, &watch_definition)
View
2  lib/guard/listeners/polling.rb
@@ -22,7 +22,7 @@ def stop
def watch_change
until @stop
start = Time.now.to_f
- files = modified_files([Dir.pwd], :all => true)
+ files = modified_files([@directory], :all => true)
@callback.call(files) unless files.empty?
nap_time = @latency - (Time.now.to_f - start)
sleep(nap_time) if nap_time > 0
View
19 lib/guard/notifier.rb
@@ -4,6 +4,7 @@
module Guard
module Notifier
+ APPLICATION_NAME = "Guard"
def self.turn_off
ENV["GUARD_NOTIFY"] = 'false'
@@ -45,8 +46,11 @@ def self.enabled?
def self.notify_mac(title, message, image, options)
require_growl # need for guard-rspec formatter that is called out of guard scope
- default_options = { :title => title, :icon => image_path(image), :name => "Guard" }
- Growl.notify message, default_options.merge(options) if enabled?
+
+ options = { :description => message, :title => title, :icon => image_path(image), :application_name => APPLICATION_NAME }.merge(options)
+ options.delete(:name)
+
+ GrowlNotify.send_notification(options) if enabled?
end
def self.notify_linux(title, message, image, options)
@@ -90,10 +94,17 @@ def self.image_level(image)
end
def self.require_growl
- require 'growl'
+ require 'growl_notify'
+
+ if GrowlNotify.application_name != APPLICATION_NAME
+ GrowlNotify.config do |c|
+ c.notifications = c.default_notifications = [ APPLICATION_NAME ]
+ c.application_name = c.notifications.first
+ end
+ end
rescue LoadError
turn_off
- UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile"
+ UI.info "Please install growl_notify gem for Mac OS X notification support and add it to your Gemfile"
end
def self.require_libnotify
View
2  lib/guard/version.rb
@@ -1,3 +1,3 @@
module Guard
- VERSION = "0.5.1" unless defined? Guard::VERSION
+ VERSION = "0.6.0" unless defined? Guard::VERSION
end
View
5 spec/guard/dsl_spec.rb
@@ -213,6 +213,11 @@
::Guard.should_receive(:add_guard).with('another', anything, {})
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => ['x','y']) }.should_not raise_error
end
+ it "should evaluate all groups when no group option is specified" do
+ ::Guard.should_receive(:add_guard).with('test', anything, {}).twice
+ ::Guard.should_receive(:add_guard).with('another', anything, {}).twice
+ lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
+ end
end
# TODO: not sure if each seperate quoting/call type needs its own test
View
95 spec/guard/notifier_spec.rb
@@ -20,17 +20,28 @@
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
end
- context "with the Growl library available" do
+ context "with the GrowlNotify library available" do
+ before do
+ module ::GrowlNotify
+ def self.config ; end
+ end
+ end
+
it "loads the library and enables the notifications" do
- subject.should_receive(:require).with('growl').and_return true
+ subject.should_receive(:require).with('growl_notify').and_return true
+ GrowlNotify.should_receive(:application_name).and_return ''
subject.turn_on
subject.should be_enabled
end
+
+ after do
+ Object.send(:remove_const, :GrowlNotify)
+ end
end
- context "without the Growl library available" do
+ context "without the GrowlNofity library available" do
it "disables the notifications" do
- subject.should_receive(:require).with('growl').and_raise LoadError
+ subject.should_receive(:require).with('growl_notify').and_raise LoadError
subject.turn_on
subject.should_not be_enabled
end
@@ -89,46 +100,54 @@
before do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
subject.stub(:require_growl)
- Object.send(:remove_const, :Growl) if defined?(Growl)
- Growl = Object.new
end
- after do
- Object.send(:remove_const, :Growl)
- end
+ context 'with growl_notify gem' do
+ before do
+ Object.send(:remove_const, :GrowlNotify) if defined?(GrowlNotify)
+ GrowlNotify = Object.new
+ end
- it "passes the notification to Growl" 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
+ after do
+ Object.send(:remove_const, :GrowlNotify)
+ end
- it "don't passes the notification to Growl if library is not available" do
- Growl.should_not_receive(:notify)
- subject.should_receive(:enabled?).and_return(true, false)
- subject.notify 'great', :title => 'Guard'
- end
+ it "passes the notification to Growl" do
+ GrowlNotify.should_receive(:send_notification).with(
+ :title => "Guard",
+ :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
+ :application_name => "Guard",
+ :description => 'great'
+ )
+ subject.notify 'great', :title => 'Guard'
+ end
- it "allows additional notification options" do
- Growl.should_receive(:notify).with("great",
- :title => "Guard",
- :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
- :name => "Guard",
- :priority => 1
- )
- subject.notify 'great', :title => 'Guard', :priority => 1
- end
+ it "don't passes the notification to Growl if library is not available" do
+ GrowlNotify.should_not_receive(:send_notification)
+ subject.should_receive(:enabled?).and_return(true, false)
+ subject.notify 'great', :title => 'Guard'
+ end
- it "allows to overwrite a default notification option" do
- Growl.should_receive(:notify).with("great",
- :title => "Guard",
- :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
- :name => "Guard-Cucumber"
- )
- subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
+ it "allows additional notification options" do
+ GrowlNotify.should_receive(:send_notification).with(
+ :title => "Guard",
+ :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
+ :application_name => "Guard",
+ :description => 'great',
+ :priority => 1
+ )
+ subject.notify 'great', :title => 'Guard', :priority => 1
+ end
+
+ it "throws out the application name since Guard should only use one Growl App Name while running" do
+ GrowlNotify.should_receive(:send_notification).with(
+ :title => "Guard",
+ :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
+ :application_name => "Guard",
+ :description => 'great'
+ )
+ subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
+ end
end
end
View
4 spec/support/listener_helper.rb
@@ -8,9 +8,11 @@ def start
end
def record_results
+ noise = %r|\.sw.$| # don't fail specs due to editor swap files, etc.
+
@results = []
@listener.on_change do |files|
- @results += files
+ @results += files.reject { |f| f =~ noise }
end
end

0 comments on commit b44a91b

Please sign in to comment.
Something went wrong with that request. Please try again.