Class: Ellington::Passenger
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ellington::Passenger
- Includes:
- Observable
- Defined in:
- lib/ellington/passenger.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
-
#ticket ⇒ Object
Returns the value of attribute ticket.
Instance Method Summary collapse
- #current_state ⇒ Object
- #current_state=(value) ⇒ Object
-
#initialize(context, route, ticket = nil) ⇒ Passenger
constructor
A new instance of Passenger.
- #lock ⇒ Object
- #locked? ⇒ Boolean
- #state_history ⇒ Object
- #transition_to(new_state) ⇒ Object
- #unlock ⇒ Object
Constructor Details
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/ellington/passenger.rb', line 6 def context @context end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
7 8 9 |
# File 'lib/ellington/passenger.rb', line 7 def route @route end |
#ticket ⇒ Object
Returns the value of attribute ticket.
6 7 8 |
# File 'lib/ellington/passenger.rb', line 6 def ticket @ticket end |
Instance Method Details
#current_state ⇒ Object
32 33 34 35 |
# File 'lib/ellington/passenger.rb', line 32 def current_state return context.current_state if context.respond_to?(:current_state) @current_state end |
#current_state=(value) ⇒ Object
37 38 39 40 |
# File 'lib/ellington/passenger.rb', line 37 def current_state=(value) return context.current_state=(value) if context.respond_to?(:current_state=) @current_state = value end |
#lock ⇒ Object
17 18 19 20 |
# File 'lib/ellington/passenger.rb', line 17 def lock return context.lock if context.respond_to?(:lock) @locked = true end |
#locked? ⇒ Boolean
27 28 29 30 |
# File 'lib/ellington/passenger.rb', line 27 def locked? return context.locked? if context.respond_to?(:locked?) @locked end |
#state_history ⇒ Object
42 43 44 |
# File 'lib/ellington/passenger.rb', line 42 def state_history @state_history ||= [] end |
#transition_to(new_state) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ellington/passenger.rb', line 46 def transition_to(new_state) if !locked? = "Cannot transition an unlocked #{self.class.name}'s state" raise Ellington::InvalidStateTransition.new() end if !route.states.can_transition?(current_state => new_state) = "Cannot transition #{self.class.name} from:#{current_state} to:#{new_state}" raise Ellington::InvalidStateTransition.new() end old_state = current_state if context.respond_to?(:transition_to) return_value = context.transition_to(new_state) 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 |
#unlock ⇒ Object
22 23 24 25 |
# File 'lib/ellington/passenger.rb', line 22 def unlock return context.unlock if context.respond_to?(:unlock) @locked = false end |