Module | Statemachine::StateBuilding |
In: |
lib/statemachine/builder.rb
|
subject | [R] |
Declare a default transition for the state. Any event that is not already handled by the state will be handled by this transition.
sm = Statemachine.build do state :locked do default :unlock, :action end end
# File lib/statemachine/builder.rb, line 114 114: def default(destination_id, action = nil) 115: @subject.default_transition = Transition.new(@subject.id, destination_id, nil, action) 116: end
Declares that the state responds to the spcified event. The event paramter should be a Symbol. The destination_id, which should also be a Symbol, is the id of the state that will event will transition into.
The 3rd action paramter is optional
sm = Statemachine.build do state :locked do event :coin, :unlocked, :unlock end end
# File lib/statemachine/builder.rb, line 73 73: def event(event, destination_id, action = nil) 74: @subject.add(Transition.new(@subject.id, destination_id, event, action)) 75: end
Declare the entry action for the state.
sm = Statemachine.build do state :locked do on_entry :lock end end
# File lib/statemachine/builder.rb, line 89 89: def on_entry(entry_action) 90: @subject.entry_action = entry_action 91: end
# File lib/statemachine/builder.rb, line 77 77: def on_event(event, options) 78: self.event(event, options[:transition_to], options[:and_perform]) 79: end