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 215
215:     def default_history(id)
216:       @subject.default_history = id
217:     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 191
191:     def on_entry_of(id, action)
192:       @statemachine.get_state(id).entry_action = action
193:     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 203
203:     def on_exit_of(id, action)
204:       @statemachine.get_state(id).exit_action = action
205:     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 179
179:     def startstate(startstate_id)
180:       @subject.startstate_id = startstate_id
181:     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 131
131:     def state(id, &block)
132:       builder = StateBuilder.new(id, @subject, @statemachine)
133:       builder.instance_eval(&block) if block
134:     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 144
144:     def superstate(id, &block)
145:       builder = SuperstateBuilder.new(id, @subject, @statemachine)
146:       builder.instance_eval(&block)
147:     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 163
163:     def trans(origin_id, event, destination_id, action = nil)
164:       origin = acquire_state_in(origin_id, @subject)
165:       origin.add(Transition.new(origin_id, destination_id, event, action))
166:     end

[Source]

     # File lib/statemachine/builder.rb, line 168
168:     def transition_from(origin_id, options)
169:       trans(origin_id, options[:on_event], options[:transition_to], options[:and_perform])
170:     end

[Validate]