Class: Ellington::Conductor
- Inherits:
-
Object
- Object
- Ellington::Conductor
- Defined in:
- lib/ellington/conductor.rb
Instance Attribute Summary collapse
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #conducting? ⇒ Boolean
- #escort(passenger) ⇒ Object
- #gather_passengers ⇒ Object
-
#initialize(route) ⇒ Conductor
constructor
A new instance of Conductor.
- #start ⇒ Object
- #stop ⇒ Object
- #verify(passenger) ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(route) ⇒ Conductor
Returns a new instance of Conductor.
7 8 9 10 |
# File 'lib/ellington/conductor.rb', line 7 def initialize(route) @route = route @conducting = false end |
Instance Attribute Details
#route ⇒ Object (readonly)
Returns the value of attribute route.
5 6 7 |
# File 'lib/ellington/conductor.rb', line 5 def route @route end |
Instance Method Details
#conducting? ⇒ Boolean
12 13 14 |
# File 'lib/ellington/conductor.rb', line 12 def conducting? @conducting end |
#escort(passenger) ⇒ Object
53 54 55 56 |
# File 'lib/ellington/conductor.rb', line 53 def escort(passenger) return unless verify(passenger) && passenger.locked? route.lines.first.board passenger end |
#gather_passengers ⇒ Object
49 50 51 |
# File 'lib/ellington/conductor.rb', line 49 def gather_passengers raise Ellington::NotImplementedError end |
#start ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ellington/conductor.rb', line 16 def start return if conducting? mutex.synchronize do @stop = false @conducting = true end @thread = Thread.new do loop do if @stop mutex.synchronize { @conducting = false } Thread.current.exit end gather_passengers.each do |passenger| escort(passenger) end end end end |
#stop ⇒ Object
37 38 39 |
# File 'lib/ellington/conductor.rb', line 37 def stop mutex.synchronize { @stop = true } end |
#verify(passenger) ⇒ Object
45 46 47 |
# File 'lib/ellington/conductor.rb', line 45 def verify(passenger) true end |
#wait ⇒ Object
41 42 43 |
# File 'lib/ellington/conductor.rb', line 41 def wait thread.join end |