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
@guards = []
options[:notify] = false if ENV["GUARD_NOTIFY"] == 'false'
options[:notify] ? Notifier.turn_on : Notifier.turn_off
options[:notify] && ENV["GUARD_NOTIFY"] != 'false' ? Notifier.turn_on : Notifier.turn_off
self
end

View File

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

View File

@ -24,6 +24,7 @@ describe Guard do
end
it "should turn on by default" do
ENV["GUARD_NOTIFY"] = nil
::Guard::Notifier.should_receive(:turn_on)
::Guard.setup(:notify => true)
end
@ -35,9 +36,7 @@ describe Guard do
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