Module: FiniteMachine

Defined in:
lib/finite_machine.rb,
lib/finite_machine/dsl.rb,
lib/finite_machine/env.rb,
lib/finite_machine/const.rb,
lib/finite_machine/hooks.rb,
lib/finite_machine/logger.rb,
lib/finite_machine/safety.rb,
lib/finite_machine/version.rb,
lib/finite_machine/callable.rb,
lib/finite_machine/listener.rb,
lib/finite_machine/observer.rb,
lib/finite_machine/catchable.rb,
lib/finite_machine/async_call.rb,
lib/finite_machine/definition.rb,
lib/finite_machine/events_map.rb,
lib/finite_machine/hook_event.rb,
lib/finite_machine/threadable.rb,
lib/finite_machine/transition.rb,
lib/finite_machine/subscribers.rb,
lib/finite_machine/state_parser.rb,
lib/finite_machine/choice_merger.rb,
lib/finite_machine/message_queue.rb,
lib/finite_machine/state_machine.rb,
lib/finite_machine/two_phase_lock.rb,
lib/finite_machine/event_definition.rb,
lib/finite_machine/state_definition.rb,
lib/finite_machine/transition_event.rb,
lib/finite_machine/transition_builder.rb,
lib/finite_machine/undefined_transition.rb

Defined Under Namespace

Modules: Catchable, Logger, Safety, Threadable, TwoPhaseLock Classes: AsyncCall, Callable, ChoiceMerger, Const, DSL, Definition, Env, EventDefinition, EventsMap, GenericDSL, HookEvent, Hooks, Listener, MessageQueue, Observer, StateDefinition, StateMachine, StateParser, Subscribers, Transition, TransitionBuilder, TransitionEvent, UndefinedTransition

Constant Summary collapse

DEFAULT_STATE =

Default state name

:none
DEFAULT_EVENT_NAME =

Initial default event name

:init
ANY_STATE =

Describe any transition state

Const.new(:any)
ANY_EVENT =

Describe any event name

Const.new(:any_event)
TransitionError =

When transition between states is invalid

Class.new(::StandardError)
CallbackError =

When failed to process callback

Class.new(::StandardError)
InvalidStateError =

Raised when transitioning to invalid state

Class.new(::ArgumentError)
InvalidEventError =
Class.new(::NoMethodError)
InvalidCallbackNameError =

Raised when a callback is defined with invalid name

Class.new(::StandardError)
NotEnoughTransitionsError =

Raised when event has no transitions

Class.new(::ArgumentError)
MissingInitialStateError =

Raised when initial event specified without state name

Class.new(::StandardError)
MessageQueueDeadError =

Raised when event queue is already dead

Class.new(::StandardError)
AlreadyDefinedError =

Raised when argument is already defined

Class.new(::ArgumentError)
VERSION =
"0.12.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger


51
52
53
# File 'lib/finite_machine.rb', line 51

def logger
  @logger
end

Class Method Details

.define(&block) ⇒ Class

A factory method for creating reusable FiniteMachine definitions

Examples:

TrafficLights = FiniteMachine.define
lights_fm_a = TrafficLights.new
lights_fm_b = TrafficLights.new

Returns:

  • (Class)

77
78
79
# File 'lib/finite_machine.rb', line 77

def define(&block)
  Class.new(Definition, &block)
end

.new(*args, **options, &block) ⇒ FiniteMachine::StateMachine

Initialize an instance of finite machine

Examples:

FiniteMachine.new do
  ...
end

Returns:


63
64
65
# File 'lib/finite_machine.rb', line 63

def new(*args, **options, &block)
  StateMachine.new(*args, **options, &block)
end