Class: Snoopit::NotificationManager
- Inherits:
-
Object
- Object
- Snoopit::NotificationManager
- Defined in:
- lib/snoopit/notification_manager.rb
Overview
Instantiates all specified Notifiers
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
Instance Method Summary collapse
- #get_notifier(name) ⇒ Object
-
#initialize(config = nil) ⇒ NotificationManager
constructor
A new instance of NotificationManager.
-
#load_notifier_config(config) ⇒ Object
Load default notifiers and configured notifiers.
-
#notify(snoopies) ⇒ Object
Invoke all notifications that this list of snoopies is subscribed to via the
snooper.json
. -
#register(notifier) ⇒ Object
Register the specified
Notifier
. -
#sniffer_notify(sniffer) ⇒ Object
Snoopies use sniffers that may or may not be associated with a notifier.
-
#unregister(notifier) ⇒ Object
Unregister the specified
Notifier
. - #unregister_by_name(notifier_name) ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ NotificationManager
Returns a new instance of NotificationManager.
8 9 10 11 12 |
# File 'lib/snoopit/notification_manager.rb', line 8 def initialize(config=nil) @active = {} @config = config load_default_notifiers unless @config.nil? end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
6 7 8 |
# File 'lib/snoopit/notification_manager.rb', line 6 def active @active end |
Instance Method Details
#get_notifier(name) ⇒ Object
40 41 42 |
# File 'lib/snoopit/notification_manager.rb', line 40 def get_notifier(name) @active[name] end |
#load_notifier_config(config) ⇒ Object
Load default notifiers and configured notifiers
15 16 17 18 19 20 |
# File 'lib/snoopit/notification_manager.rb', line 15 def load_notifier_config(config) @config = config load_default_notifiers load = @config['load'] load_files(load) unless load.nil? end |
#notify(snoopies) ⇒ Object
Invoke all notifications that this list of snoopies is subscribed to via the snooper.json
46 47 48 49 50 51 52 |
# File 'lib/snoopit/notification_manager.rb', line 46 def notify(snoopies) snoopies.each do |snoopy| snoopy.sniffers.each do |sniffer| sniffer_notify(sniffer) end end end |
#register(notifier) ⇒ Object
Register the specified Notifier
24 25 26 27 28 |
# File 'lib/snoopit/notification_manager.rb', line 24 def register(notifier) raise NameError.new "Notifier missing valid name: #{notifier.inspect}" if notifier.name.nil? Snoopit.logger.debug "Registering notifier #{notifier.name}" @active[notifier.name] = notifier end |
#sniffer_notify(sniffer) ⇒ Object
Snoopies use sniffers that may or may not be associated with a notifier
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/snoopit/notification_manager.rb', line 56 def sniffer_notify(sniffer) = sniffer sniffer.notifiers.each do |key, value| n = @active[key] next if n.nil? .each do || n.notify(, value) end end end |
#unregister(notifier) ⇒ Object
Unregister the specified Notifier
32 33 34 |
# File 'lib/snoopit/notification_manager.rb', line 32 def unregister(notifier) self.unregister_by_name notifier.name end |
#unregister_by_name(notifier_name) ⇒ Object
36 37 38 |
# File 'lib/snoopit/notification_manager.rb', line 36 def unregister_by_name(notifier_name) @active.delete notifier_name end |