transitions
transitions copied to clipboard
Add "failure" callback to defined events
Initial discussion started in the following issue ( https://github.com/troessner/transitions/issues/113 )
Like the success callback on events, we should have a matching failure callback. An event definition may look something like the following:
event :available, :failure => :reorder do
transitions :to => :available, :from => [:out_of_stock], :guard => lambda { |product| product.in_stock > 0 }
end
The failure callback should take the following:
- symbol or lambda block like many other callbacks within the gem
- single callback or an array of callbacks like the rest of the gem
A few areas to consider where a failure condition may come into play
- The state does not transition because you are moving from one state that can't move to another state (to -> from's are not valid)
- A guard condition is hit preventing a successful transition
- An
on_transitionscenario halts the transition from being successful. An exception may be raised within anon_transitioncallback.
@troessner - Let me know if anything looks out of line with the initial plan for this.
Excellent summary. One more thing: i think right now the "success" callback is more of an "execute at the end" callback. I dont think we are checking there for any success whatsoever. Just saying that we might need to change the flow there as well.
Sounds good. I'll have to check for that condition when I crack into the code a bit more :)
@troessner - Have not forgot about this but still have not had time to get into it. Just wanted to give you a heads up on this.
No problem, noted..:)
+1