I am looking to implement a state machine in one of my models, and I have been considering the state_machine gem which seems popular and appears to have a nice, simple API.
Anyways, it seems like there is no concept of persisting the state of the model, since the documentation does not illustrate any way to map the state to a DB property using ActiveRecord or any other supported ORM. I would expect to load an object from the DB, check its state if desired, and based on its state allow certain events/transitions to take place.
- Am I completely missing something here or is there no way to persist the current state?
- If not, how can a transient state useful for any persisted model whose state changes over long periods of time?
- Should I be used a different plugin, something more suited for workflows?
As far as the documentation goes, the state machine library works with any attribute, either one that’s created with
attr_accessor, an@-instance variable, or a database column. It does seem to be your responsibility to callsaveon the record if any changes have been made, though.