state_machine
https://github.com/pluginaweek/state_machine
Ruby
Adds support for creating state machines for attributes on any Ruby class
StateMachine::Machine#after_failure
Creates a callback that will be invoked *after* a transition failures to
be performed so long as the given requirements match the transition.
See +before_transition+ for a description of the possible configurations
for defining callbacks. *Note* however that you cannot define the state
requirements in these callbacks. You may only define event requirements.
= The callback
Failure callbacks get invoked whenever an event fails to execute. This
can happen when no transition is available, a +before+ callback halts
execution, or the action associated with this machine fails to succeed.
In any of these cases, any failure callback that matches the attempted
transition will be run.
For example,
class Vehicle
state_machine do
after_failure do |vehicle, transition|
logger.error "vehicle #{vehicle} failed to transition on #{transition.event}"
end
after_failure :on => :ignite, :do => :log_ignition_failure
...
end
endEdit
git clone [email protected]:pluginaweek/state_machine.git
cd state_machine
open lib/state_machine/machine.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-StateMachine--Machine-after_failure-for-pr
# Commit to gitgit add lib/state_machine/machine.rbgit commit -m "better docs for StateMachine::Machine#after_failure"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-StateMachine--Machine-after_failure-for-pr
hub pull-request
# Celebrate!