class Ellington::Passenger
Attributes
context[RW]
state_history[R]
ticket[RW]
Public Class Methods
new(context, ticket: Ellington::Ticket.new, state_history: [])
click to toggle source
Calls superclass method
# File lib/ellington/passenger.rb, line 9 def initialize(context, ticket: Ellington::Ticket.new, state_history: []) @context = context @ticket = ticket @state_history = state_history super context end
Public Instance Methods
current_state()
click to toggle source
# File lib/ellington/passenger.rb, line 16 def current_state return context.current_state if context.respond_to?(:current_state) @current_state end
current_state=(value)
click to toggle source
# File lib/ellington/passenger.rb, line 21 def current_state=(value) return context.current_state=(value) if context.respond_to?(:current_state=) @current_state = value end
state_history_includes?(*states)
click to toggle source
# File lib/ellington/passenger.rb, line 26 def state_history_includes?(*states) (state_history & states).length == states.length end
transition_to(new_state, state_jacket: nil)
click to toggle source
# File lib/ellington/passenger.rb, line 30 def transition_to(new_state, state_jacket: nil) if !state_jacket.can_transition?(current_state => new_state) message = "Cannot transition #{self.class.name} from:#{current_state} to:#{new_state}" raise Ellington::InvalidStateTransition.new(message) end old_state = current_state if context.respond_to?(:transition_to) return_value = context.transition_to(new_state, state_jacket: state_jacket) else self.current_state = new_state end state_history << new_state changed notify_observers Ellington::TransitionInfo.new(self, old_state, new_state) return_value || new_state end