There’s no shortage of Ruby state machine libraries, but when we needed to implement a formal state machine we don’t find one which met all of our requirements.
I had a same problem in my project.What i needed was a polymorphic class that could have multiple number of state machines in it. Depending on the the relation the appropriate state machine should be used.
Since AASM State Machine does not supports multiple state machine in a single class. So i tried to achive it through state_machine gem with namespaces BUT AGAIN we can not have same states under namespaced state machine in a single class.
How to do it?
My basic requirement was to have a state machine that should be easily composable with other Ruby objects.So what i need to do was to define a state machine as a separate class and selectively apply itto our Rails models. since Mongodb supports embeded obects. I could use it to store states in it.
We wanted a state machine that could be easily integrated with other Ruby objects. So we decided to define a state machine as a separate class and selectively apply it to our Rails models. We were using MongoDB, so we embedded these objects.
classCarStateMachineincludeMongoid::Documentfield:stateembedded_in:call# no need for name space and we can use AASM directlystate_machine:state,:initial=>:freshdo#states: fresh, scheduled, lead, succeedevent:scheduledotransition[:fresh,:schedule]=>:scheduledend#...#...endend