/
growl.rb
64 lines (56 loc) · 2.01 KB
/
growl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module UniformNotifier
class Growl < Base
@growl = nil
def self.active?
@growl
end
def self.out_of_channel_notify( message )
return unless active?
notify( message )
end
def self.setup_connection( growl )
setup_connection_growl(growl)
rescue LoadError
begin
setup_connection_gntp(growl)
rescue LoadError
@growl = nil
raise NotificationError.new( 'You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp`' )
end
end
def self.setup_connection_growl( growl )
return unless growl
require 'ruby-growl'
@password = growl.instance_of?(Hash) ? growl[:password] : nil
@growl = ::Growl.new('localhost',
'uniform_notifier',
[ 'uniform_notifier' ],
nil,
@password)
notify 'Uniform Notifier Growl has been turned on'
end
def self.setup_connection_gntp( growl )
return unless growl
require 'ruby_gntp'
@password = growl.instance_of?(Hash) ? growl[:password] : nil
@growl = GNTP.new('uniform_notifier', 'localhost', @password, 23053)
@growl.register({:notifications => [{
:name => 'uniform_notifier',
:enabled => true,
}]})
notify 'Uniform Notifier Growl has been turned on (using GNTP)'
end
private
def self.notify( message )
if defined?(::Growl) && @growl.is_a?(::Growl)
@growl.notify( 'uniform_notifier', 'Uniform Notifier', message )
elsif defined?(::GNTP) && @growl.is_a?(::GNTP)
@growl.notify({
:name => 'uniform_notifier',
:title => 'Uniform Notifier',
:text => message
})
end
end
end
end