class Stately::Machine

A Stately::Machine is a container for Stately::States.

Attributes

start[R]
state_attr[R]
states[R]

Public Class Methods

new(attr_name, start) click to toggle source

Sets up a new instance of Stately::Machine

# File lib/stately/machine.rb, line 7
def initialize(attr_name, start)
  @state_attr = attr_name
  @start = start
  @states = [State.new(@start)]
end

Public Instance Methods

state(name, opts={}, &block) click to toggle source

Define a new Stately::State and add it to this Stately::Machine.

@param [String] name The name of the state. This is also stored in the instance object's

state attribute.

@param [Hash] opts Optionally, a method name can be defined as this state's action, if it

can't be inferred from the name.
# File lib/stately/machine.rb, line 19
def state(name, opts={}, &block)
  @states.delete_if { |s| s.name == name }

  action = opts ? opts[:action] : nil
  @states << State.new(name, action, &block)
end