No commit activity in last 3 years
No release in over 3 years
Define triggers and transitios, what else? Well... Filter
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 0.1.1
 Project Readme

Lab42::StateMachine

Build Status Gem Version Code Climate Issue Count Test Coverage

Usage

The DSL

Define a State Machine by giving it a name and defining states with their transitions in a block:

Example: A Simple Definition

    Lab42::StateMachine.new "my machine" do
      state :start do
        trigger %r{\A[aeiou]} do |acc, _|
           [nil, [acc.first+1, acc.last]]
         end
      end
    end

Be aware that a trigger block needs to accept at least one argument

Example: This raises an ArgumentError

  machine = 
    Lab42::StateMachine.new "my machine" do
      state :start do
        trigger %r{\A[aeiou]} do
           [nil, nil]
         end
      end
    end
  expect{ machine.run(nil, ["abc"]) }.to raise_error(ArgumentError)

Also there is one state you must not defined, the :stop state

Example: Defining the :stop state

   expect do
     Lab42::StateMachine.new "booom, don't stop" do
        state :stop do
          trigger true, :start
        end
     end
   end.to raise_error(FrozenError)
    

Author

Copyright © 2020 Robert Dober mailto: robert.dober@gmail.com

LICENSE

Same as Elixir -- 😉 --, which is Apache License v2.0. Please refer to LICENSE for details.

SPDX-License-Identifier: Apache-2.0