Module: Statemachine

Defined in:
lib/statemachine/state.rb,
lib/statemachine/builder.rb,
lib/statemachine/version.rb,
lib/statemachine/superstate.rb,
lib/statemachine/transition.rb,
lib/statemachine/statemachine.rb,
lib/statemachine/stub_context.rb,
lib/statemachine/generate/util.rb,
lib/statemachine/action_invokation.rb,
lib/statemachine/generate/src_builder.rb,
lib/statemachine/generate/java/java_statemachine.rb,
lib/statemachine/generate/dot_graph/dot_graph_statemachine.rb

Defined Under Namespace

Modules: ActionInvokation, Generate, StateBuilding, SuperstateBuilding, VERSION Classes: Builder, State, StateBuilder, Statemachine, StatemachineBuilder, StatemachineException, StubContext, Superstate, SuperstateBuilder, Transition, TransitionMissingException

Class Method Summary collapse

Class Method Details

.build(statemachine = nil, &block) ⇒ Object

The starting point for building instances of Statemachine.

The block passed in should contain all the declarations for all states, events, and actions with in the statemachine.

Sample: Turnstyle

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

An optional statemachine parameter may be passed in to modify an existing statemachine instance.

Actions: Where ever an action paramter is used, it may take on one of three forms:

1. Symbols: will execute a method by the same name on the _context_
2. String: Ruby code that will be executed within the binding of the _context_
3. Proc: Will be executed within the binding of the _context_

See Statemachine::SuperstateBuilding See Statemachine::StateBuilding



26
27
28
29
30
31
# File 'lib/statemachine/builder.rb', line 26

def self.build(statemachine = nil, &block)
  builder = statemachine ? StatemachineBuilder.new(statemachine) : StatemachineBuilder.new
  builder.instance_eval(&block)
  builder.statemachine.reset
  return builder.statemachine
end