Module Statemachine::StateBuilding
In: lib/statemachine/builder.rb

The builder module used to declare states.

Methods

default   event   on_entry   on_event   on_exit  

Attributes

subject  [R] 

Public Instance methods

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

[Source]

     # 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

[Source]

    # 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

[Source]

    # File lib/statemachine/builder.rb, line 89
89:     def on_entry(entry_action)
90:       @subject.entry_action = entry_action
91:     end

[Source]

    # 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

Declare the exit action for the state.

  sm = Statemachine.build do
    state :locked do
      on_exit :unlock
    end
  end

[Source]

     # File lib/statemachine/builder.rb, line 101
101:     def on_exit(exit_action)
102:       @subject.exit_action = exit_action
103:     end

[Validate]