Skip to content

Commit

Permalink
Added #Growl hash support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 8, 2009
1 parent 058b8fb commit ce03429
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.rdoc
Expand Up @@ -27,6 +27,10 @@ Ruby growlnotify 'bindings'.
n.stick! n.stick!
end end


# OR

Growl :message => 'Invoked via Growl with hash', :icon => 'jpeg', :title => 'Growl

== Features == Features


* Check availability with Growl#installed? * Check availability with Growl#installed?
Expand Down
10 changes: 7 additions & 3 deletions lib/growl/growl.rb
Expand Up @@ -54,14 +54,18 @@ class Base
# Initialize with optional +block+, which is then # Initialize with optional +block+, which is then
# instance evaled or yielded depending on the blocks arity. # instance evaled or yielded depending on the blocks arity.


def initialize &block def initialize options = {}, &block
@args = [] @args = []
if block_given? if block_given?
if block.arity > 0 if block.arity > 0
yield self yield self
else else
self.instance_eval &block self.instance_eval &block
end end
else
options.each do |key, value|
send :"#{key}=", value
end
end end
end end


Expand Down Expand Up @@ -133,6 +137,6 @@ def self.switches


end end


def Growl *args, &block def Growl options = {}, &block
Growl.new(*args, &block).run Growl.new(options, &block).run
end end
4 changes: 4 additions & 0 deletions spec/growl_spec.rb
Expand Up @@ -22,6 +22,10 @@
it "should accept a block, running immediately after" do it "should accept a block, running immediately after" do
Growl { |n| n.message = 'Invoked via Growl' } Growl { |n| n.message = 'Invoked via Growl' }
end end

it "should accept a hash" do
Growl :message => 'Invoked via Growl with hash', :icon => 'jpeg', :title => 'Growl'
end
end end


describe "#run" do describe "#run" do
Expand Down

0 comments on commit ce03429

Please sign in to comment.