Class: Boxafe::Notifier
- Inherits:
-
Object
show all
- Defined in:
- lib/boxafe/notifier.rb
Defined Under Namespace
Classes: Growl, NotificationCenter
Constant Summary
collapse
- IMPLEMENTATIONS =
%w(growl notification_center)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Notifier
Returns a new instance of Notifier.
38
39
40
|
# File 'lib/boxafe/notifier.rb', line 38
def initialize options = {}
@options = { title: 'Boxafe' }.merge options
end
|
Class Method Details
.notifier(options = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/boxafe/notifier.rb', line 6
def self.notifier options = {}
if options[:notify] == true
platform_notifier options
elsif IMPLEMENTATIONS.include?(name = options[:notify].to_s)
notifier_instance name, options
elsif options.key?(:notify) and options[:notify] != false
raise Boxafe::Error, "Unknown notification type #{options[:notify].inspect}"
end
end
|
.notifier_instance(name, options = {}) ⇒ Object
16
17
18
19
|
# File 'lib/boxafe/notifier.rb', line 16
def self.notifier_instance name, options = {}
impl = Boxafe::Notifier.const_get(name.gsub(/(?:\A|_)(.)/){ $1.upcase })
impl.available? ? impl.new(options) : nil
end
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/boxafe/notifier.rb', line 21
def self.platform_notifier options = {}
candidates = case RbConfig::CONFIG['host_os']
when /darwin/i
%w(notification_center growl)
else
[]
end
candidates.each do |name|
notifier = notifier_instance name, options
return notifier if notifier
end
nil
end
|