Permalink
Browse files

Added #notify_{ok,info,warning,error} and images

  • Loading branch information...
1 parent 6aabd4d commit ecb35e85694a0f25a008822b1935c3aad3161a06 @tj committed Apr 9, 2009
View
@@ -9,12 +9,6 @@ module Growl
class Error < StandardError; end
- #--
- # Singleton methods
- #++
-
- module_function
-
##
# Display a growl notification +message+, with +options+
# documented below. Alternatively a +block+ may be passed
@@ -35,35 +29,45 @@ class Error < StandardError; end
def notify message = nil, options = {}, &block
return unless installed?
- options.merge! :message => message unless block
+ options.merge! :message => message if message
Growl.new(options, &block).run
end
+ module_function :notify
+
+ %w( ok info warning error ).each do |type|
+ define_method :"notify_#{type}" do |message, *args|
+ options = args.first || {}
+ image = File.join File.expand_path(File.dirname(__FILE__)), 'images', "#{type}.png"
+ notify message, options.merge(:image => image)
+ end
+ module_function :"notify_#{type}"
+ end
##
# Execute +args+ against the binary.
- def exec *args
+ def self.exec *args
Kernel.system BIN, *args
end
##
# Return the version triple of the binary.
- def version
+ def self.version
@version ||= `#{BIN} --version`.split[1]
end
##
# Check if the binary is installed and accessable.
- def installed?
+ def self.installed?
!! version
end
##
# Return an instance of Growl::Base or nil when not installed.
- def new *args, &block
+ def self.new *args, &block
return unless installed?
Base.new *args, &block
end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -34,6 +34,14 @@
end
end
+ %w( ok info warning error ).each do |type|
+ describe "#notify_#{type}" do
+ it "should display #{type} notifications" do
+ Growl.send(:"notify_#{type}", "Hello", :title => type).should be_true
+ end
+ end
+ end
+
describe "#run" do
it "should fail when no message is present" do
lambda { Growl.new.run }.should raise_error(Growl::Error, /message required/)

0 comments on commit ecb35e8

Please sign in to comment.