Fixed Guard::Notifier (when growl/libnotify not present)

This commit is contained in:
Thibaud Guillaume-Gentil 2011-05-08 21:56:46 +02:00
parent 5352528530
commit 1e5ab84b3a
3 changed files with 8 additions and 10 deletions

View File

@ -16,8 +16,7 @@ module Guard
@listener = Listener.select_and_init @listener = Listener.select_and_init
@guards = [] @guards = []
options[:notify] = false if ENV["GUARD_NOTIFY"] == 'false' options[:notify] && ENV["GUARD_NOTIFY"] != 'false' ? Notifier.turn_on : Notifier.turn_off
options[:notify] ? Notifier.turn_on : Notifier.turn_off
self self
end end

View File

@ -5,11 +5,11 @@ module Guard
module Notifier module Notifier
def self.turn_off def self.turn_off
@disable = true ENV["GUARD_NOTIFY"] = 'false'
end end
def self.turn_on def self.turn_on
@disable = false ENV["GUARD_NOTIFY"] = 'true'
case Config::CONFIG['target_os'] case Config::CONFIG['target_os']
when /darwin/i when /darwin/i
require_growl require_growl
@ -19,7 +19,7 @@ module Guard
end end
def self.notify(message, options = {}) def self.notify(message, options = {})
unless @disable unless disabled?
image = options[:image] || :success image = options[:image] || :success
title = options[:title] || "Guard" title = options[:title] || "Guard"
case Config::CONFIG['target_os'] case Config::CONFIG['target_os']
@ -32,7 +32,7 @@ module Guard
end end
def self.disabled? def self.disabled?
@disable ENV["GUARD_NOTIFY"] == 'false'
end end
private private
@ -55,14 +55,14 @@ module Guard
def self.require_growl def self.require_growl
require 'growl' require 'growl'
rescue LoadError rescue LoadError
@disable = true 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 gem for Mac OS X notification support and add it to your Gemfile"
end end
def self.require_libnotify def self.require_libnotify
require 'libnotify' require 'libnotify'
rescue LoadError rescue LoadError
@disable = true turn_off
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile" UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
end end

View File

@ -24,6 +24,7 @@ describe Guard do
end end
it "should turn on by default" do it "should turn on by default" do
ENV["GUARD_NOTIFY"] = nil
::Guard::Notifier.should_receive(:turn_on) ::Guard::Notifier.should_receive(:turn_on)
::Guard.setup(:notify => true) ::Guard.setup(:notify => true)
end end
@ -35,9 +36,7 @@ describe Guard do
it "should turn off notifier if env[GUARD_NOTIFY] is false" do it "should turn off notifier if env[GUARD_NOTIFY] is false" do
::Guard::Notifier.should_receive(:turn_off) ::Guard::Notifier.should_receive(:turn_off)
ENV["GUARD_NOTIFY"] = 'false'
::Guard.setup(:notify => true) ::Guard.setup(:notify => true)
ENV["GUARD_NOTIFY"] = nil
end end
end end