Class: Statemachine::StatemachineBuilder

Inherits:
Builder
  • Object
show all
Includes:
SuperstateBuilding
Defined in:
lib/statemachine/builder.rb

Overview

Created by Statemachine.build as the root context for building the statemachine.

Instance Attribute Summary

Attributes included from SuperstateBuilding

#subject

Attributes inherited from Builder

#statemachine

Instance Method Summary collapse

Methods included from SuperstateBuilding

#default_history, #on_entry_of, #on_exit_of, #startstate, #state, #superstate, #trans, #transition_from

Constructor Details

#initialize(statemachine = Statemachine.new) ⇒ StatemachineBuilder

Returns a new instance of StatemachineBuilder.



248
249
250
251
# File 'lib/statemachine/builder.rb', line 248

def initialize(statemachine = Statemachine.new)
  super statemachine
  @subject = @statemachine.root
end

Instance Method Details

#context(a_context) ⇒ Object

Used the set the context of the statemahine within the builder.

sm = Statemachine.build do
  ...
  context MyContext.new
end

Statemachine.context may also be used.



261
262
263
264
# File 'lib/statemachine/builder.rb', line 261

def context(a_context)
  @statemachine.context = a_context
  a_context.statemachine = @statemachine if a_context.respond_to?(:statemachine=)
end

#stub_context(options = {}) ⇒ Object

Stubs the context. This makes statemachine immediately useable, even if functionless. The stub will print all the actions called so it’s nice for trial runs.

sm = Statemachine.build do
  ...
  stub_context :verbose => true
end

Statemachine.context may also be used.



275
276
277
278
# File 'lib/statemachine/builder.rb', line 275

def stub_context(options={})
  require 'statemachine/stub_context'
  context StubContext.new(options)
end