Module: Mealy::DSL

Defined in:
lib/mealy/dsl.rb

Overview

The class level DSL for defining machines.

Instance Method Summary collapse

Instance Method Details

#finish(&block) ⇒ Object

final FSM state


48
49
50
# File 'lib/mealy/dsl.rb', line 48

def finish(&block)
  @finish_data = block
end

#initial_state(sym, &block) ⇒ Object

Declares the initial state of the FSM.


12
13
14
# File 'lib/mealy/dsl.rb', line 12

def initial_state(sym, &block)
  @start_data = [sym, block]
end

#read(state:, on: ANY, &block) ⇒ Object

An FSM loop


40
41
42
43
44
# File 'lib/mealy/dsl.rb', line 40

def read(state:, on: ANY, &block)
  [* state].each do |one_state|
    transition(from: one_state, to: one_state, on: on, &block)
  end
end

#transition(from:, to:, on: ANY, &block) {|input, from, to| ... } ⇒ Object

An FSM transition.

Yield Parameters:

  • input

    The read input, that matches the rules Label

  • from

    The state we are transitioning away from

  • to

    The state we are transitioning to


27
28
29
30
31
32
# File 'lib/mealy/dsl.rb', line 27

def transition(from:, to:, on: ANY, &block)
  hash = { HelperMethods.Label(on) => { to: to, block: block } }
  [* from].each do |origin|
    @transitions[origin] = @transitions[origin].merge(hash)
  end
end