Class: Statemachine::State
- Inherits:
-
Object
- Object
- Statemachine::State
- Defined in:
- lib/statemachine/state.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
- #default_transition ⇒ Object
-
#entry_action ⇒ Object
Returns the value of attribute entry_action.
-
#exit_action ⇒ Object
Returns the value of attribute exit_action.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#statemachine ⇒ Object
readonly
Returns the value of attribute statemachine.
-
#superstate ⇒ Object
readonly
Returns the value of attribute superstate.
Instance Method Summary collapse
- #activate ⇒ Object
- #add(transition) ⇒ Object
- #concrete? ⇒ Boolean
- #enter(args = []) ⇒ Object
- #exit(args) ⇒ Object
-
#initialize(id, superstate, state_machine) ⇒ State
constructor
A new instance of State.
- #non_default_transition_for(event) ⇒ Object
- #reset ⇒ Object
- #resolve_startstate ⇒ Object
- #to_s ⇒ Object
- #transition_for(event) ⇒ Object
- #transitions ⇒ Object
Constructor Details
#initialize(id, superstate, state_machine) ⇒ State
Returns a new instance of State.
9 10 11 12 13 14 15 |
# File 'lib/statemachine/state.rb', line 9 def initialize(id, superstate, state_machine) @id = id @superstate = superstate @statemachine = state_machine @transitions = {} @exit_action = @entry_action = nil end |
Instance Attribute Details
#default_transition ⇒ Object
31 32 33 34 35 |
# File 'lib/statemachine/state.rb', line 31 def default_transition return @default_transition if @default_transition return @superstate.default_transition if @superstate return nil end |
#entry_action ⇒ Object
Returns the value of attribute entry_action.
6 7 8 |
# File 'lib/statemachine/state.rb', line 6 def entry_action @entry_action end |
#exit_action ⇒ Object
Returns the value of attribute exit_action.
6 7 8 |
# File 'lib/statemachine/state.rb', line 6 def exit_action @exit_action end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/statemachine/state.rb', line 5 def id @id end |
#statemachine ⇒ Object (readonly)
Returns the value of attribute statemachine.
5 6 7 |
# File 'lib/statemachine/state.rb', line 5 def statemachine @statemachine end |
#superstate ⇒ Object (readonly)
Returns the value of attribute superstate.
5 6 7 |
# File 'lib/statemachine/state.rb', line 5 def superstate @superstate end |
Instance Method Details
#activate ⇒ Object
54 55 56 |
# File 'lib/statemachine/state.rb', line 54 def activate @statemachine.state = self end |
#add(transition) ⇒ Object
17 18 19 |
# File 'lib/statemachine/state.rb', line 17 def add(transition) @transitions[transition.event] = transition end |
#concrete? ⇒ Boolean
58 59 60 |
# File 'lib/statemachine/state.rb', line 58 def concrete? return true end |
#enter(args = []) ⇒ Object
49 50 51 52 |
# File 'lib/statemachine/state.rb', line 49 def enter(args=[]) @statemachine.trace("\tentering #{self}") @statemachine.invoke_action(@entry_action, args, "entry action for #{self}") if @entry_action end |
#exit(args) ⇒ Object
43 44 45 46 47 |
# File 'lib/statemachine/state.rb', line 43 def exit(args) @statemachine.trace("\texiting #{self}") @statemachine.invoke_action(@exit_action, args, "exit action for #{self}") if @exit_action @superstate.substate_exiting(self) if @superstate end |
#non_default_transition_for(event) ⇒ Object
25 26 27 28 29 |
# File 'lib/statemachine/state.rb', line 25 def non_default_transition_for(event) transition = @transitions[event] transition = @superstate.non_default_transition_for(event) if @superstate and not transition return transition end |
#reset ⇒ Object
66 67 |
# File 'lib/statemachine/state.rb', line 66 def reset end |
#resolve_startstate ⇒ Object
62 63 64 |
# File 'lib/statemachine/state.rb', line 62 def resolve_startstate return self end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/statemachine/state.rb', line 69 def to_s return "'#{id}' state" end |
#transition_for(event) ⇒ Object
37 38 39 40 41 |
# File 'lib/statemachine/state.rb', line 37 def transition_for(event) transition = non_default_transition_for(event) transition = default_transition if not transition return transition end |
#transitions ⇒ Object
21 22 23 |
# File 'lib/statemachine/state.rb', line 21 def transitions return @superstate ? @transitions.merge(@superstate.transitions) : @transitions end |