/SimplyStated

I'm n ur object, making it a state machine

Primary LanguageRubyGNU General Public License v3.0GPL-3.0

SimplyStated

Simply stated is a simple yet extensible API to define state machine behaviour when creating a class.

Getting started

It’s quite easy ; let’s imagine a simple state machine with 2 states and one transition by state :

          ---goto_other-->
[initial]                  [other]
          <-goto_initial--

You can define it as follows :

require 'simply_stated'
class Machine
  include SimplyStated::Stated
  define_states do |d|
    d.state :initial do |s|
      s.transition :goto_other, :other
    end
    d.state :other do |s|
      s.transition :goto_initial, :initial
    end
  end
end

Then, you can use as follows :

> machine = Machine.new
> machine.state.name
=> :initial
> machine.goto_other
> machine.state.name
=> :other
> machine.goto_initial
> machine.state.name
=> :initial

See SimplyStated::Stated for a fuller exemple.

License

Wanna read, use, reuse, change ? By all means please do, it’s under GPL V3.

see LICENSE for more details about the GPL V3, it’s pretty awesome