Storing workflows (state machines) in the DB. What

2019-04-09 19:46发布

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条回答
干净又极端
2楼-- · 2019-04-09 20:33

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.

查看更多
登录 后发表回答