master/lib/guard/notifier.rb

45 lines
1.0 KiB
Ruby
Raw Normal View History

require 'rbconfig'
2010-10-03 21:00:33 +00:00
require 'pathname'
case Config::CONFIG['target_os']
when /darwin/i
2010-10-03 21:00:33 +00:00
require 'growl'
when /linux/i
2010-10-03 21:00:33 +00:00
require 'libnotify'
end
module Guard
module Notifier
def self.notify(message, options = {})
unless ENV["GUARD_ENV"] == "test"
image = options[:image] || :success
title = options[:title] || "Guard"
case Config::CONFIG['target_os']
when /darwin/i
2010-10-03 21:00:33 +00:00
Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard"
when /linux/i
2010-10-03 21:00:33 +00:00
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
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
end
end