Merge pull request #51 from indirect/guard
--- This change allows guard plugins (like guard-rspec) to pass options (like :priority) up to the Growl notifier. With this change, things like indirect/rspec-guard@d2f01d69a7 are possible, and the growl notification colors can be customized depending on the outcome of the spec run. Conflicts: lib/guard/notifier.rb
This commit is contained in:
commit
320706e2f5
@ -1,3 +1,9 @@
|
|||||||
|
## Master
|
||||||
|
|
||||||
|
### New features:
|
||||||
|
|
||||||
|
- Pull request [#51](https://github.com/guard/guard/pull/51): Allow options (like :priority) to be passed through to the Notifier ([@indirect](https://github.com/indirect) and [@netzpirat](https://github.com/netzpirat))
|
||||||
|
|
||||||
## 0.4.0.rc - May 28, 2011
|
## 0.4.0.rc - May 28, 2011
|
||||||
|
|
||||||
### Bugs fixes:
|
### Bugs fixes:
|
||||||
@ -111,4 +117,4 @@
|
|||||||
### New features:
|
### New features:
|
||||||
|
|
||||||
- Improved listeners support (`rb-fsevent` & `rb-inotify`). ([@thibaudgg](https://github.com/thibaudgg))
|
- Improved listeners support (`rb-fsevent` & `rb-inotify`). ([@thibaudgg](https://github.com/thibaudgg))
|
||||||
- Added polling listening fallback. ([@thibaudgg](https://github.com/thibaudgg))
|
- Added polling listening fallback. ([@thibaudgg](https://github.com/thibaudgg))
|
||||||
|
@ -23,18 +23,16 @@ module Guard
|
|||||||
|
|
||||||
def self.notify(message, options = {})
|
def self.notify(message, options = {})
|
||||||
if enabled?
|
if enabled?
|
||||||
image = options[:image] || :success
|
image = options.delete(:image) || :success
|
||||||
title = options[:title] || "Guard"
|
title = options.delete(:title) || "Guard"
|
||||||
|
|
||||||
case Config::CONFIG['target_os']
|
case Config::CONFIG['target_os']
|
||||||
when /darwin/i
|
when /darwin/i
|
||||||
require_growl # need for guard-rspec formatter that is called out of guard scope
|
notify_mac(title, message, image, options)
|
||||||
Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard"
|
|
||||||
when /linux/i
|
when /linux/i
|
||||||
require_libnotify # need for guard-rspec formatter that is called out of guard scope
|
notify_linux(title, message, image, options)
|
||||||
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
|
|
||||||
when /mswin|mingw/i
|
when /mswin|mingw/i
|
||||||
require_rbnotifu
|
notify_windows(title, message, image, options)
|
||||||
Notifu.show :message => message, :title => title, :type => image_level(image), :time => 3
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -45,6 +43,24 @@ module Guard
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.notify_linux(title, message, image, options)
|
||||||
|
require_libnotify # need for guard-rspec formatter that is called out of guard scope
|
||||||
|
default_options = { :body => message, :summary => title, :icon_path => image_path(image) }
|
||||||
|
Libnotify.show default_options.merge(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.notify_windows(title, message, image, options)
|
||||||
|
require_rbnotifu # need for guard-rspec formatter that is called out of guard scope
|
||||||
|
default_options = { :message => message, :title => title, :type => image_level(image), :time => 3 }
|
||||||
|
Notifu.show default_options.merge(options)
|
||||||
|
end
|
||||||
|
|
||||||
def self.image_path(image)
|
def self.image_path(image)
|
||||||
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
|
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
|
||||||
case image
|
case image
|
||||||
@ -72,7 +88,7 @@ module Guard
|
|||||||
:info
|
:info
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.require_growl
|
def self.require_growl
|
||||||
require 'growl'
|
require 'growl'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
@ -63,6 +63,8 @@ describe Guard::Notifier do
|
|||||||
Growl = Object.new
|
Growl = Object.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
around { Object.send(:remove_const, :Growl) if defined?(Growl) }
|
||||||
|
|
||||||
it "passes the notification to Growl" do
|
it "passes the notification to Growl" do
|
||||||
Growl.should_receive(:notify).with("great",
|
Growl.should_receive(:notify).with("great",
|
||||||
:title => "Guard",
|
:title => "Guard",
|
||||||
@ -71,6 +73,25 @@ describe Guard::Notifier do
|
|||||||
)
|
)
|
||||||
subject.notify 'great', :title => 'Guard'
|
subject.notify 'great', :title => 'Guard'
|
||||||
end
|
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 "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"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "on Linux" do
|
context "on Linux" do
|
||||||
@ -80,6 +101,8 @@ describe Guard::Notifier do
|
|||||||
Libnotify = Object.new
|
Libnotify = Object.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
around { Object.send(:remove_const, :Libnotify) if defined?(Libnotify) }
|
||||||
|
|
||||||
it "passes the notification to Libnotify" do
|
it "passes the notification to Libnotify" do
|
||||||
Libnotify.should_receive(:show).with(
|
Libnotify.should_receive(:show).with(
|
||||||
:body => "great",
|
:body => "great",
|
||||||
@ -88,6 +111,25 @@ describe Guard::Notifier do
|
|||||||
)
|
)
|
||||||
subject.notify 'great', :title => 'Guard'
|
subject.notify 'great', :title => 'Guard'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows additional notification options" do
|
||||||
|
Libnotify.should_receive(:show).with(
|
||||||
|
:body => "great",
|
||||||
|
:summary => 'Guard',
|
||||||
|
:icon_path => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
|
||||||
|
:urgency => :critical
|
||||||
|
)
|
||||||
|
subject.notify 'great', :title => 'Guard', :urgency => :critical
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows to overwrite a default notification option" do
|
||||||
|
Libnotify.should_receive(:show).with(
|
||||||
|
:body => "great",
|
||||||
|
:summary => 'Guard',
|
||||||
|
:icon_path => '~/.guard/success.png'
|
||||||
|
)
|
||||||
|
subject.notify 'great', :title => 'Guard', :icon_path => '~/.guard/success.png'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "on Windows" do
|
context "on Windows" do
|
||||||
@ -97,6 +139,8 @@ describe Guard::Notifier do
|
|||||||
Notifu = Object.new
|
Notifu = Object.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
around { Object.send(:remove_const, :Notifu) if defined?(Notify) }
|
||||||
|
|
||||||
it "passes the notification to rb-notifu" do
|
it "passes the notification to rb-notifu" do
|
||||||
Notifu.should_receive(:show).with(
|
Notifu.should_receive(:show).with(
|
||||||
:message => "great",
|
:message => "great",
|
||||||
@ -106,6 +150,27 @@ describe Guard::Notifier do
|
|||||||
)
|
)
|
||||||
subject.notify 'great', :title => 'Guard'
|
subject.notify 'great', :title => 'Guard'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows additional notification options" do
|
||||||
|
Notifu.should_receive(:show).with(
|
||||||
|
:message => "great",
|
||||||
|
:title => 'Guard',
|
||||||
|
:type => :info,
|
||||||
|
:time => 3,
|
||||||
|
:nosound => true
|
||||||
|
)
|
||||||
|
subject.notify 'great', :title => 'Guard', :nosound => true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows to overwrite a default notification option" do
|
||||||
|
Notifu.should_receive(:show).with(
|
||||||
|
:message => "great",
|
||||||
|
:title => 'Guard',
|
||||||
|
:type => :info,
|
||||||
|
:time => 10
|
||||||
|
)
|
||||||
|
subject.notify 'great', :title => 'Guard', :time => 10
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user