Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Growl#notify docs

  • Loading branch information...
commit 0918ad9d1599749c7ee43af9ce5e4f32b972a7d1 1 parent eead16f
@tj authored
Showing with 28 additions and 9 deletions.
  1. +24 −5 lib/growl/growl.rb
  2. +4 −4 spec/growl_spec.rb
View
29 lib/growl/growl.rb
@@ -16,6 +16,30 @@ class Error < StandardError; end
module_function
##
+ # Display a growl notification +message+, with +options+
+ # documented below. Alternatively a +block+ may be passed
+ # which is then instance evaluated or yielded to the block.
+ #
+ # This method is simply returns nil when growlnotify
+ # is not installed, as growl notifications should never
+ # be the only means of communication between your application
+ # and your user.
+ #
+ # === Examples
+ #
+ # Growl.notify 'Hello'
+ # Growl.notify 'Hello', :title => 'TJ Says:', :sticky => true
+ # Growl.notify { |n| n.message = 'Hello'; n.sticky! }
+ # Growl.notify { self.message = 'Hello'; sticky! }
+ #
+
+ def notify message = nil, options = {}, &block
+ return unless installed?
+ options.merge! :message => message unless block
+ Growl.new(options, &block).run
+ end
+
+ ##
# Execute +args+ against the binary.
def exec *args
@@ -136,9 +160,4 @@ def self.switches
end
-end
-
-def Growl options = {}, &block
- return unless Growl.installed?
- Growl.new(options, &block).run
end
View
8 spec/growl_spec.rb
@@ -18,19 +18,19 @@
@growl.message = 'Hello World'
end
- describe "#Growl" do
+ describe "#notify" do
it "should accept a block, running immediately after" do
- Growl { |n| n.message = 'Invoked via Growl' }
+ Growl.notify { |n| n.message = 'Invoked via Growl' }.should be_true
end
it "should accept a hash" do
- Growl :message => 'Invoked via Growl with hash', :icon => 'jpeg', :title => 'Growl'
+ Growl.notify('Invoked via Growl with hash', :icon => 'jpeg', :title => 'Growl').should be_true
end
it "should return nil when not installed" do
Growl.stub!(:installed?).and_return(false)
Growl.new.should be_nil
- lambda { Growl :message => 'I should never show :)' }.should_not raise_error
+ lambda { Growl.notify 'I should never show :)' }.should_not raise_error
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.