MINT Statemachine Gem extensions¶ ↑
This branch contains extensions that we implemented as part of the MINT project to run multimodal applications.
It is based on the great Statemachine Ruby Library, which enables simple creation of full-features Finite Statemachines that has been originally developed by Micah Martin.
To get started, please look at the documentation on the Statemachine website: slagyr.github.com/statemachine
Changes ¶ ↑
Multiple actions¶ ↑
Instead of a single action, multiple actions can be defined for a transition by using an array.
sm = Statemachine.build do |smb| smb.trans :cold, :fire, :hot, [:cook, Proc.new { @tasty = true;true }, "@shape = 'fettucini'"] end
Redefinition of states without loosing transitions¶ ↑
In a statemachine definition you can pass another statemachine and replace for the new statemachine a state with a superstate without loosing the original transitions.
In this example the state :unlocked of @old_sm gets replaced by a super state.
@sm = Statemachine.build @old_sm do superstate :unlocked do trans :u1, :u, :u2 trans :u2, :e, :maintenance end end
Transitions can fail¶ ↑
Each action that is called during a transaction has to return true for the transition to suceed. Otherwise the entire transition is assumed as failed and the statemachine remains in its origin state.
Transitions can be spontaneous (eventless)¶ ↑
In this example the statemachine will first enter the inital u1 state but then directly will do a transition to u2.
@sm = Statemachine.build @old_sm do superstate :unlocked do trans :u1, nil , :u2 trans :u2, :e, :maintenance end end
Support for parallel running states¶ ↑
After sending the :go event, the statemachine of this example will end up in a [:locked,:on] setting.
@sm = Statemachine.build do trans :start,:go,:p parallel :p do statemachine :s1 do superstate :operative do trans :locked, :coin, :unlocked trans :unlocked, :coin, :locked end end statemachine :s2 do superstate :onoff do trans :on, :toggle, :off trans :off, :toggle, :on end end end end
Support for GemBundler¶ ↑
rake make_spec can be used to create a gemspec file that is required for GemBundler integration.
Project website¶ ↑
License¶ ↑
Copyright © 2010-2012 Sebastian Feuerstack, Jessica Colnago Copyright © 2006-2010 Micah Martin
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA