Class: DirectoryWatcher::Notifier
- Inherits:
-
Object
- Object
- DirectoryWatcher::Notifier
- Defined in:
- lib/directory_watcher/notifier.rb
Overview
A Notifier pull Event instances from the give queue and sends them to all of the Observers it knows about.
Instance Method Summary collapse
-
#initialize(config, observers) ⇒ Notifier
constructor
Create a new Notifier that pulls events off the given notification_queue from the config, and sends them to the listed observers.
-
#run ⇒ Object
Notify all the observers of all the available events in the queue.
Methods included from Logable
Methods included from Threaded
#_activity_thread, #continue_on_error=, #continue_on_error?, #finished_iterations?, #interval, #interval=, #iterations, #join, #maximum_iterations, #maximum_iterations=, #pause, #resume, #running?, #start, #status, #stop, #wait
Constructor Details
#initialize(config, observers) ⇒ Notifier
Create a new Notifier that pulls events off the given notification_queue from the config, and sends them to the listed observers.
11 12 13 14 15 |
# 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 |
Instance Method Details
#run ⇒ Object
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.
21 22 23 24 25 26 27 28 29 30 31 |
# 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 |