Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3, allow app_name in Growl notifications #13

Merged
merged 2 commits into from
Mar 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ or
require 'notify'
Notify.notify "title", "message"

Notify also allows passing in an app name to replace the default "ruby":

require 'notify'
Notify.notify "title", "message", { app_name: "My App" }

Command
---------

Expand Down
17 changes: 11 additions & 6 deletions lib/notify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ def self.html_escape(text)
end

dir = File.dirname(__FILE__)
if ENV['NOTIFY']
require File.join(dir, "notify/#{ENV['NOTIFY']}")
else
Dir[File.join(dir, "notify/*.rb")].each do |filename|
break if Notify.methods.include?(:notify)
require filename
begin
if ENV['NOTIFY']
require File.join(dir, "notify/#{ENV['NOTIFY']}")
else
Dir[File.join(dir, "notify/*.rb")].each do |filename|
break if Notify.methods.include?(:notify)
require filename
end
end
rescue LoadError
# A safeguard against bad libraries or edge-case errors.
puts "Notify can't find the library specified."
end

module Notify
Expand Down
4 changes: 2 additions & 2 deletions lib/notify/ruby-growl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Notify
begin
require 'ruby-growl'

@@growl = Growl.new 'localhost', 'ruby'
@@growl.add_notification 'notify'
def self.notify(title, message, option = {})
@@growl = Growl.new 'localhost', option[:app_name] || "ruby"
@@growl.add_notification 'notify'
@@growl.notify 'notify', title, message, option[:priority] || 0, option[:sticky] || false
end
rescue LoadError
Expand Down
2 changes: 1 addition & 1 deletion lib/notify/ruby_gntp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Notify
require 'ruby_gntp'

def self.notify(title, message, option = {})
GNTP.notify :app_name => "ruby", :title => title, :text => message, :icon => option[:icon] || "", :sticky => option[:sticky] || false
GNTP.notify :app_name => option[:app_name] || "ruby", :title => title, :text => message, :icon => option[:icon] || "", :sticky => option[:sticky] || false
end
rescue LoadError
end
Expand Down