4

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

Alessandro De Simone
  • 4,085
  • 6
  • 28
  • 41

1 Answers1

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.

Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • Thanks for the hint, but I know very little about metaprogramming. Could you be more specific ? in the way you said can I use the gem workflow ? (I don't want to rewrite how work a state machine) – Alessandro De Simone Sep 28 '11 at 21:45
  • you don't need to rewrite the gem --- you'll be using the gem at runtime. this is advanced stuff though. – Jesse Wolgamott Sep 28 '11 at 23:16