module GenericStateMachine::DSL

Constants

Hook

Struct describing a hook

Transition

Struct describing a transition

Public Instance Methods

describe(&block) click to toggle source

Method is used to describe the properties the GSM should have @raise [GenericStateMachine::Errors::DSLError]

# File dsl/dsl.rb, line 11
def describe(&block)
  raise GenericStateMachine::Errors::DSLError, '#describe needs a block' unless block_given?

  dsl = StateMachineDSL.create &block

  _create_state_machine dsl
end

Private Instance Methods

_create_state_machine(dsl) click to toggle source

Actually create an instance of StateMachine using a DSL object @param [StateMachineDSL] @raise [GenericStateMachine::Errors::DSLError]

# File dsl/dsl.rb, line 35
def _create_state_machine(dsl)
  transitions = dsl.transitions.collect do |t|
    _transition_from_struct t
  end

  GenericStateMachine::StateMachineFactory.create start: dsl.starting,
                                                  transitions: transitions, hooks: dsl.hooks
end
_transition_from_struct(transition) click to toggle source

Helper creating a Transition instance @param [Transition] transition

# File dsl/dsl.rb, line 48
def _transition_from_struct(transition)
  GenericStateMachine::Transition.new transition.from, transition.to, transition.condition
end