master/lib/guard/notifier.rb
Scott Parrish f3d49ee81e Made slight alteration to Guard::Notifier. pulled out logic into #should_send? to allow for stubbing in tests and added #turn_on to allow more flexibility for when things are or are not sent.
Notifier Specs changed to make pass, expanded and to use new notify strategies.  NOTE mac tests not tested.
Guard::Dsl changed massively.  overall strategy was to decouple to evaluate_guardfile into "getting the data" and "using the data" parts.  this provides the ability to pass a string that contains the contents of a guardfile, or to pass a filename for a guardfile as well as reading the default loc for a guardfile.
Dsl specs changed massivly to support new style of Dsl
listener/linux_spec changed to add a few :long_running tags and to alter some paths to correct values
listener/polling_spec changed to add a few :long_running tags and to alter some paths to correct values
2011-05-05 03:05:58 -06:00

77 lines
1.8 KiB
Ruby

require 'rbconfig'
require 'pathname'
module Guard
module Notifier
@enable = true #todo verify this is the right default
def self.turn_off
@enable = false
end
def self.turn_on
@enable = true
end
def self.should_send?
#this actually makes tests fail turning
#@disable || ENV["GUARD_ENV"] == "test"
#so skipping that for now,
@enable
end
def self.notify(message, options = {})
if should_send?()
image = options[:image] || :success
title = options[:title] || "Guard"
case Config::CONFIG['target_os']
when /darwin/i
if growl_installed?
Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard"
end
when /linux/i
if libnotify_installed?
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
end
end
end
end
private
def self.image_path(image)
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
case image
when :failed
images_path.join("failed.png").to_s
when :pending
images_path.join("pending.png").to_s
when :success
images_path.join("success.png").to_s
else
# path given
image
end
end
def self.growl_installed?
@installed ||= begin
require 'growl'
true
rescue LoadError
UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile"
false
end
end
def self.libnotify_installed?
@installed ||= begin
require 'libnotify'
true
rescue LoadError
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
false
end
end
end
end