class DirectoryWatcher::Notifier
A Notifier pull Event instances from the give queue and sends them to all of the Observers it knows about.
Public Class Methods
new( config, observers )
click to toggle source
Create a new Notifier that pulls events off the given notification_queue from the config, and sends them to the listed observers.
# File lib/directory_watcher/notifier.rb, line 11 def initialize( config, observers ) @config = config @observers = observers self.interval = 0.01 # yes this is a fast loop end
Public Instance Methods
run()
click to toggle source
Notify all the observers of all the available events in the queue. If there are 2 or more events in a row that are the same, then they are collapsed into a single event.
# File lib/directory_watcher/notifier.rb, line 21 def run previous_event = nil until queue.empty? do event = queue.deq next if previous_event == event @observers.each do |observer, func| send_event_to_observer( observer, func, event ) end previous_event = event end end
Private Instance Methods
queue()
click to toggle source
# File lib/directory_watcher/notifier.rb, line 37 def queue @config.notification_queue end
send_event_to_observer( observer, func, event )
click to toggle source
Send the given event to the given observer using the given function.
Capture any exceptions that have, swallow them and send them to stderr.
# File lib/directory_watcher/notifier.rb, line 44 def send_event_to_observer( observer, func, event ) observer.send(func, event) rescue Exception => e $stderr.puts "Called #{observer}##{func}(#{event}) and all I got was this lousy exception #{e}" end