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

The builder module used to declare superstates.

Methods

Attributes

subject  [R] 

Public Instance methods

Used to specify the default state held by the history pseudo state of the superstate.

  sm = Statemachine.build do
    superstate :operational do
      default_history :state_id
    end
  end

[Source]

     # File lib/statemachine/builder.rb, line 207
207:     def default_history(id)
208:       @subject.default_history = id
209:     end

Allows the declaration of entry actions without using the state method. id is identifies the state to which the entry action will be added.

  sm = Statemachine.build do
    trans :locked, :coin, :unlocked
    on_entry_of :unlocked, :unlock
  end

[Source]

     # File lib/statemachine/builder.rb, line 183
183:     def on_entry_of(id, action)
184:       @statemachine.get_state(id).entry_action = action
185:     end

Allows the declaration of exit actions without using the state method. id is identifies the state to which the exit action will be added.

  sm = Statemachine.build do
    trans :locked, :coin, :unlocked
    on_exit_of :locked, :unlock
  end

[Source]

     # File lib/statemachine/builder.rb, line 195
195:     def on_exit_of(id, action)
196:       @statemachine.get_state(id).exit_action = action
197:     end

Specifies the startstate for the statemachine or superstate. The state must exist within the scope.

sm = Statemachine.build do

  startstate :locked

end

[Source]

     # File lib/statemachine/builder.rb, line 171
171:     def startstate(startstate_id)
172:       @subject.startstate_id = startstate_id
173:     end

Define a state within the statemachine or superstate.

  sm = Statemachine.build do
    state :locked do
      #define the state
    end
  end

[Source]

     # File lib/statemachine/builder.rb, line 127
127:     def state(id, &block)
128:       builder = StateBuilder.new(id, @subject, @statemachine)
129:       builder.instance_eval(&block) if block
130:     end

Define a superstate within the statemachine or superstate.

  sm = Statemachine.build do
    superstate :operational do
      #define superstate
    end
  end

[Source]

     # File lib/statemachine/builder.rb, line 140
140:     def superstate(id, &block)
141:       builder = SuperstateBuilder.new(id, @subject, @statemachine)
142:       builder.instance_eval(&block)
143:     end

Declares a transition within the superstate or statemachine. The origin_id, a Symbol, identifies the starting state for this transition. The state identified by origin_id will be created within the statemachine or superstate which this transition is declared. 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. This method will not create destination states within the current statemachine of superstate. If the state destination state should exist here, that declare with with the state method or declare a transition starting at the state.

  sm = Statemachine.build do
    trans :locked, :coin, :unlocked, :unlock
  end

[Source]

     # File lib/statemachine/builder.rb, line 159
159:     def trans(origin_id, event, destination_id, action = nil)
160:       origin = acquire_state_in(origin_id, @subject)
161:       origin.add(Transition.new(origin_id, destination_id, event, action))
162:     end

[Validate]