Class: Statemachine::Transition
- Inherits:
-
Object
- Object
- Statemachine::Transition
- Defined in:
- lib/statemachine/transition.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#destination_id ⇒ Object
Returns the value of attribute destination_id.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#origin_id ⇒ Object
readonly
Returns the value of attribute origin_id.
Instance Method Summary collapse
- #exits_and_entries(origin, destination) ⇒ Object
-
#initialize(origin_id, destination_id, event, action) ⇒ Transition
constructor
A new instance of Transition.
- #invoke(origin, statemachine, args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(origin_id, destination_id, event, action) ⇒ Transition
Returns a new instance of Transition.
8 9 10 11 12 13 |
# File 'lib/statemachine/transition.rb', line 8 def initialize(origin_id, destination_id, event, action) @origin_id = origin_id @destination_id = destination_id @event = event @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/statemachine/transition.rb', line 5 def action @action end |
#destination_id ⇒ Object
Returns the value of attribute destination_id.
6 7 8 |
# File 'lib/statemachine/transition.rb', line 6 def destination_id @destination_id end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
5 6 7 |
# File 'lib/statemachine/transition.rb', line 5 def event @event end |
#origin_id ⇒ Object (readonly)
Returns the value of attribute origin_id.
5 6 7 |
# File 'lib/statemachine/transition.rb', line 5 def origin_id @origin_id end |
Instance Method Details
#exits_and_entries(origin, destination) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/statemachine/transition.rb', line 35 def exits_and_entries(origin, destination) return [], [] if origin == destination exits = [] entries = exits_and_entries_helper(exits, origin, destination) return exits, entries.reverse end |
#invoke(origin, statemachine, args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/statemachine/transition.rb', line 15 def invoke(origin, statemachine, args) destination = statemachine.get_state(@destination_id) exits, entries = exits_and_entries(origin, destination) exits.each { |exited_state| exited_state.exit(args) } if @action result = origin.statemachine.invoke_action(@action, args, "transition action from #{origin} invoked by '#{@event}' event") if @action transition = !(result === false) else transition = true end if transition terminal_state = entries.last terminal_state.activate if terminal_state entries.each { |entered_state| entered_state.enter(args) } end end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/statemachine/transition.rb', line 42 def to_s return "#{@origin_id} ---#{@event}---> #{@destination_id} : #{action}" end |