[英]Any recommendations for implementing a user-defined workflow in Ruby?
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? 还有其他解决方案吗?
Try Ruote . 尝试Ruote 。 It is a full fledged work-flow engine built on top of Ruby. 它是基于Ruby构建的完整的工作流程引擎。
Documentation: 文档:
Ruote Documentation page 1 Ruote文档页面1
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: 假设您为模型使用了user_id和字符串,则电子邮件的状态下拉列表将像这样填充:
@states = State.find(:conditions => {
:user_id => current_user.id,
:model_name => 'State',
:parent_id => 4 #so you get the possible states that follow "New"
})
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 编辑:添加了parent_id和acts_as_tree参考
Are you looking for something like Finite State Machine? 您是否在寻找有限状态机之类的东西?
http://slagyr.github.com/statemachine/ http://slagyr.github.com/statemachine/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.