troessner/transitions — pull request #55 by squidfunk (2012-06-21 14:47:30+00:00)
Title: Allow to pass Procs as callbacks

Hi there,

I incorporated transitions into a class and really like how it works. However, since I need to manipulate a lot of instance specific variables and call methods within the scope of the instance, the lambda syntax is very ugly. Additionally, the :on_transition and :guard take a lot of space, so I propose some tweaks here:

* you can now pass Procs as callbacks, which are evaluated in the scope of the instance.
* introduced synonyms :if for :guard and :do for :on_transition

This makes the following code:

transitions from: [:one_state], :to => :another,
guard: -> _ { _.call_a_method and _.another_method },
on_transition: -> _ { _.error _.last, :blablabla }

... far more readable:

transitions from: [:one_state], :to => :another,
:if => proc { call_a_method and another_method },
:do => proc { error last, :blablabla }

Within my fork, I removed .rvmrc and .travis.yml, so you might consider not merging them, if you decide to do. Maybe you like it.

All the best,
Martin