From 1e5ab84b3a2436c8100e0b3252d4ba26e5b5f0f5 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Sun, 8 May 2011 21:56:46 +0200 Subject: [PATCH] Fixed Guard::Notifier (when growl/libnotify not present) --- lib/guard.rb | 3 +-- lib/guard/notifier.rb | 12 ++++++------ spec/guard_spec.rb | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/guard.rb b/lib/guard.rb index 12c35a9..ed3756c 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -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 diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index 27e92df..421cb70 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -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 diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index bf3faa8..fa17a99 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -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