Storing workflows (state machines) in the DB. What's the best way?

社会主义新天地 提交于 2019-12-09 18:38:40

问题


I am using workflow gem (htts://rubygems.org/gems/workflow), inside a RoR model (User) to model a simple state machine (actually many workflow with the same root).

The state machine is hardcoded in the model, but I need a way to allow the administrators to customize the workflows. So, I think, that I have to find out a solution to store all the workflows (the state machines) to the DB.

Do you know some lib or gems to do that ? (I have seen many state machines gem but they don't manage workflow stored in the tables)

Many Thanks


回答1:


Don't know of any gems... but, you could use meta-programming to load how your workflows function.

Let's say you could store your workflow definitions in the database. Something like:

Account.new.extend_workflow(@user.account_workflows)

The #extend_workflow and the account_workflows are completely custom and written by you... in this way, your Account could have custom state machine definitions and rulesets.

Not for the faint of heart, but could solve your problem here.



来源:https://stackoverflow.com/questions/7586559/storing-workflows-state-machines-in-the-db-whats-the-best-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!