workflow 0.3 gem released

Better error messages

Helpful error messages is one of the hardest thing to achieve. Thanks to the workflow user Kyle Burton for the proposal regarding transitions to an illegal state! Now if you have not defined e.g. solved event but try to transition to it, you will get more meaningful message like Event[solve]'s transitions_to[solved] is not a declared state. and immediately know, what to fix.

Separation of concerns

Intermixing of transition graph definition (states, transitions) on the one side and implementation of the actions on the other side for a bigger state machine can introduce clutter.

To reduce this clutter it is now possible to use state entry- and exit- hooks defined through a naming convention. For example, if there is a state :pending, then instead of using a block:

state :pending do
  on_entry do
    # your implementation here
  end
end

you can hook in by defining method

def on_pending_exit(new_state, event, *args)
  # your implementation here
end

anywhere in your class. You can also use a simpler function signature like def on_pending_exit(*args) if your are not interested in arguments. Please note: def on_pending_exit() with an empty list would not work.

If both a function with a name according to naming convention and the on_entry/on_exit block are given, then only on_entry/on_exit block is used.

Have fun!

You can easily install the newest version with

sudo gem install workflow

Comments

blog comments powered by Disqus