对于在 Ruby 中实现用户定义的工作流程有什么建议吗?

发布于 2024-08-29 01:06:01 字数 168 浏览 3 评论 0原文

我有兴趣创建一个系统,用户可以在其中定义工作流程中的步骤。 有没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

划一舟意中人 2024-09-05 01:06:01

尝试 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

淡笑忘祈一世凡恋 2024-09-05 01:06:01

对于状态机,我建议另一种: workflow

所有 gems 使用“预定义”的原因states 是因为通常有一些与状态相关的 ruby​​ 代码:你会说“当从这个状态转换到这个状态时,执行这个代码”或者“在从这里转换到那里之前,检查这个 ruby​​ 守卫”。如果状态不是某种程度的“硬编码”,则无法实现这种功能。

如果您只需要一个文本字段,而无需执行任何代码,则可以使用一个简单的“状态”模型,其中包含:

  • 名称(字符串)
  • 创建此状态的 user_id(如果您正在使用某些东西,则为 group_id更复杂)
  • 此状态所针对的模型。这可以是整数或字符串,具体取决于您的喜好。
  • 状态parent_id(可以为空)。通常, acts_as_tree 会帮助你解决这个问题。

假设您为模型使用 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"
})

如果您确实需要在某些转换/防护处执行某些代码,您将需要使用预定义的状态。这也是可能的,但您必须稍微更改一下您的要求:您将让他们从列表中“激活”其中一些状态,而不是让用户定义自己的状态。那么,“用户已激活此状态”将只是您的状态系统上的另一个“守卫”。

编辑:添加了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:

  • A name (string)
  • The user_id that created this state (or a group_id if you are using something more sophisticated)
  • The model this state is for. This could be either an integer or a string, depending on your tastes.
  • The state parent_id (can be null). Typically, acts_as_tree will help you with this one.

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:

@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

ぇ气 2024-09-05 01:06:01

您在寻找类似有限状态机的东西吗?

http://slagyr.github.com/statemachine/

Are you looking for something like Finite State Machine?

http://slagyr.github.com/statemachine/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文