对于在 Ruby 中实现用户定义的工作流程有什么建议吗?
我有兴趣创建一个系统,用户可以在其中定义工作流程中的步骤。 有没有 gem 已经可以处理这个问题了?我考虑过其中一个状态机宝石,但它们似乎都适用于预定义的状态。我一直在想也许我可以对各个步骤类型使用状态机...电子邮件步骤可以有几个状态[新建、已分配、完成],并且工作流程可能只是这些有状态步骤的列表。还有其他解决方案吗?
I'm interested in creating a system where the user can define the steps in a workflow.
Is there a gem that already handles this? I thought about one of the state machine gems, but they all seem to be for pre-defined states. I've been thinking maybe i can use state machine for the individual step types... An email step could have a few states [New, Assigned, Done], and the workflow could just be lists of these stateful steps. Are there other solutions out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试 Ruote。它是一个构建在 Ruby 之上的成熟工作流引擎。
文档:
Ruote 文档第 1 页
Ruote 文档页面 2
创建 Ruote 流程
Try Ruote. It is a full fledged work-flow engine built on top of Ruby.
Documentation:
Ruote Documentation page 1
Ruote Documentation page 2
Creating a Ruote Process
对于状态机,我建议另一种: workflow
所有 gems 使用“预定义”的原因states 是因为通常有一些与状态相关的 ruby 代码:你会说“当从这个状态转换到这个状态时,执行这个代码”或者“在从这里转换到那里之前,检查这个 ruby 守卫”。如果状态不是某种程度的“硬编码”,则无法实现这种功能。
如果您只需要一个文本字段,而无需执行任何代码,则可以使用一个简单的“状态”模型,其中包含:
假设您为模型使用 user_id 和字符串,则电子邮件的状态下拉列表将按如下方式填充:
如果您确实需要在某些转换/防护处执行某些代码,您将需要使用预定义的状态。这也是可能的,但您必须稍微更改一下您的要求:您将让他们从列表中“激活”其中一些状态,而不是让用户定义自己的状态。那么,“用户已激活此状态”将只是您的状态系统上的另一个“守卫”。
编辑:添加了parent_id和acts_as_tree参考
For state machine let me suggest another one: workflow
The reason why all the gems use "pre-defined" states is because generally there's some ruby code involved with states: you say things like "when a transition from this state to this state happens, execute this code" or "before transitioning from here to there, check this ruby guard". This kind of functionality can't be implemented if the states are not somewhat "hard-coded".
If you just need a text field, without any code being executed at no point, you can just use a simple "State" model, containing:
Assuming that you use a user_id and a string for the model, then the state drop down for an email would be populated like this:
If you do need to execute some code at some transition/guard, you will need to use predefined states. It's also possible, but you would have to change your requirements a bit: instead of letting users define their own states, you would leave them "activate" some of them from a list. Then, the "user has activated this state" would be just another "guard" on your state system.
EDIT: Added the parent_id and acts_as_tree reference
您在寻找类似有限状态机的东西吗?
http://slagyr.github.com/statemachine/
Are you looking for something like Finite State Machine?
http://slagyr.github.com/statemachine/