class FiniteMachine::Definition

Responsible for defining a standalone state machine

@api public

Public Class Methods

add_deferred(deferred) click to toggle source

Add deferred

@param [Proc] deferred

the deferred execution

@return [Array<Proc>]

@api private

# File lib/finite_machine/definition.rb, line 85
def self.add_deferred(deferred)
  deferreds << deferred
end
any_event() click to toggle source

The any event constant

@example

on_before(any_event) { ... }

@return [FiniteMachine::Const]

@api public

# File lib/finite_machine/definition.rb, line 16
def self.any_event
  ANY_EVENT
end
any_state() click to toggle source

The any state constant

@example

event :go, any_state => :green

@example

on_enter(any_state) { ... }

@return [FiniteMachine::Const]

@api public

# File lib/finite_machine/definition.rb, line 31
def self.any_state
  ANY_STATE
end
deferreds() click to toggle source

The state machine deferreds

@return [Array<Proc>]

@api private

# File lib/finite_machine/definition.rb, line 73
def self.deferreds
  @deferreds ||= []
end
inherited(subclass) click to toggle source

Add deferred methods to the subclass

@param [Class] subclass

the inheriting subclass

@return [void]

@api private

Calls superclass method
# File lib/finite_machine/definition.rb, line 62
def self.inherited(subclass)
  super

  deferreds.each { |d| subclass.add_deferred(d) }
end
method_missing(method_name, *arguments, &block) click to toggle source

Delay lookup of DSL method

@param [Symbol] method_name

the method name

@param [Array] arguments

the method arguments

@return [void]

@api private

# File lib/finite_machine/definition.rb, line 99
def self.method_missing(method_name, *arguments, &block)
  deferred = proc do |name, args, blok, object|
    object.send(name, *args, &blok)
  end
  deferred = deferred.curry(4)[method_name][arguments][block]
  add_deferred(deferred)
end
new(*args) click to toggle source

Initialize a StateMachine

@example

class Engine < FiniteMachine::Definition
  ...
end

engine = Engine.new

@return [FiniteMachine::StateMachine]

@api public

# File lib/finite_machine/definition.rb, line 47
def self.new(*args)
  context = self
  FiniteMachine.new(*args) do
    context.deferreds.each { |d| d.call(self) }
  end
end