class Ellington::Station
Attributes
line[RW]
line_class[RW]
Public Instance Methods
call(passenger, _=nil)
click to toggle source
# File lib/ellington/station.rb, line 72 def call(passenger, _=nil) if can_engage?(passenger) attendant = Ellington::Attendant.new(self) passenger.add_observer attendant engage_and_transition passenger passenger.delete_observer attendant raise Ellington::AttendantDisapproves unless attendant.approve? changed notify_observers Ellington::StationInfo.new(self, passenger, attendant.passenger_transitions.first) end passenger end
can_engage?(passenger)
click to toggle source
# File lib/ellington/station.rb, line 49 def can_engage?(passenger) return false unless route.states.can_transition?(passenger.current_state => states.keys) return false if passenger.state_history_includes?(passed) true end
engage(passenger)
click to toggle source
# File lib/ellington/station.rb, line 55 def engage(passenger) raise Ellington::NotImplementedError end
engage_and_transition(passenger)
click to toggle source
# File lib/ellington/station.rb, line 59 def engage_and_transition(passenger) begin if !!engage(passenger) pass_passenger passenger else fail_passenger passenger end rescue StandardError => e Ellington.logger.error "Failure while engaging passenger! #{e}" if Ellington.logger error_passenger passenger end end
error_passenger(passenger)
click to toggle source
# File lib/ellington/station.rb, line 94 def error_passenger(passenger) passenger.transition_to errored, state_jacket: route.states end
errored()
click to toggle source
# File lib/ellington/station.rb, line 34 def errored @error_state ||= state_name(:error) end
fail_passenger(passenger)
click to toggle source
# File lib/ellington/station.rb, line 90 def fail_passenger(passenger) passenger.transition_to failed, state_jacket: route.states end
failed()
click to toggle source
# File lib/ellington/station.rb, line 30 def failed @fail_state ||= state_name(:fail) end
initial_states()
click to toggle source
# File lib/ellington/station.rb, line 12 def initial_states route.states.keys.select do |state| route.states.can_transition?(state => states.keys) end end
name()
click to toggle source
# File lib/ellington/station.rb, line 18 def name @name ||= "#{line_class.name} #{self.class.name}" end
pass_passenger(passenger)
click to toggle source
# File lib/ellington/station.rb, line 86 def pass_passenger(passenger) passenger.transition_to passed, state_jacket: route.states end
passed()
click to toggle source
# File lib/ellington/station.rb, line 26 def passed @pass_state ||= state_name(:pass) end
state(passenger)
click to toggle source
# File lib/ellington/station.rb, line 98 def state(passenger) case passenger.current_state when passed then "PASS" when failed then "FAIL" when errored then "ERROR" end end
state_name(state)
click to toggle source
# File lib/ellington/station.rb, line 22 def state_name(state) "#{state.to_s.upcase} #{name}" end
states()
click to toggle source
# File lib/ellington/station.rb, line 38 def states @states ||= begin catalog = StateJacket::Catalog.new catalog.add passed catalog.add failed catalog.add errored => [ passed, failed, errored ] catalog.lock catalog end end