Class: MailRoom::Coordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_room/coordinator.rb

Overview

Coordinate the mailbox watchers

Author:

  • Tony Pitale

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailboxes) ⇒ Coordinator

build watchers for a set of mailboxes



9
10
11
12
13
# File 'lib/mail_room/coordinator.rb', line 9

def initialize(mailboxes)
  self.watchers = []

  mailboxes.each {|box| self.watchers << MailboxWatcher.new(box)}
end

Instance Attribute Details

#runningObject Also known as: running?

Returns the value of attribute running.



5
6
7
# File 'lib/mail_room/coordinator.rb', line 5

def running
  @running
end

#watchersObject

Returns the value of attribute watchers.



5
6
7
# File 'lib/mail_room/coordinator.rb', line 5

def watchers
  @watchers
end

Instance Method Details

#quitObject

quit each of the watchers when we’re done running



29
30
31
# File 'lib/mail_room/coordinator.rb', line 29

def quit
  watchers.each(&:quit)
end

#runObject

start each of the watchers to running



18
19
20
21
22
23
24
25
26
# File 'lib/mail_room/coordinator.rb', line 18

def run
  watchers.each(&:run)
  
  self.running = true
  
  sleep_while_running
ensure
  quit
end