statemachine
Nothing to display jet.
Nothing to display jet.
I have a lot of code in my project like the following:
class Animal < ActiveRecord::Base
state_machine do
around_transition :on => :sure do |animal, _, block|
animal.transaction do
block.call
animal.do_things_on_sure
end
end
end
end
around_transition looks ugly and repeats for many classes.. Lets refactor it. More under the cut
State Machine comes to the rescue when models in your application need statuses and events.
There is a #state_machine gem for #ruby.
I recommend you to spend some time studying basics before you start using it with #rails. More under the cut
I wrote a #microgem for a simple validation a state of the object with #statemachine More under the cut