简体   繁体   English

是否有具有用户定义状态的 Ruby on Rails 工作流 gem?

[英]Are there Ruby on Rails workflow gems with user-defined states?

I develops Ruby on Rails application and now looking for workflow gem that allows configure states without any programming.我开发了 Ruby on Rails 应用程序,现在正在寻找无需任何编程即可配置状态的工作流 gem。

I found some gems: rails_workflow , state_machine , workflow .我发现了一些宝石: rails_workflowstate_machineworkflow

But as I understood, these gems assumes that states will be hard-coded, eg workflow gem states:但据我了解,这些 gem 假定状态将是硬编码的,例如工作流gem 状态:

class Article
  include Workflow
  workflow do
    state :new do
      event :submit, :transitions_to => :awaiting_review
    end
    state :awaiting_review do
      event :review, :transitions_to => :being_reviewed
    end
    state :being_reviewed do
      event :accept, :transitions_to => :accepted
      event :reject, :transitions_to => :rejected
    end
    state :accepted
    state :rejected
  end
end

I need that my application users states could configure states and transitions conditions theyself, without developer.我需要我的应用程序用户状态可以自己配置状态和转换条件,而无需开发人员。

Redmine already has this feature, but it's ready system, not gem that I can connect to my application Redmine已经有这个功能,但它是现成的系统,而不是我可以连接到我的应用程序的 gem

Are there any gems with such features?有没有具有这种特征的宝石?

I devised the following solution from my comment earlier.我根据之前的评论设计了以下解决方案。 Use the gem state_machine , and then you can define the transitions of your state machine using ActiveRecord like this:使用 gem state_machine ,然后您可以使用 ActiveRecord 定义状态机的转换,如下所示:

Define a Transition model with columns, 'to', 'from' and 'on'.定义一个包含“to”、“from”和“on”列的转换模型。 They all will have string as their data-type.它们都将string作为其数据类型。

The states will be defined as follows:状态定义如下:

Transition.create(:from => "parked", :to => "idling", :on => "ignite")

After this you need to modify your transitions method as follows:在此之后,您需要按如下方式修改您的转换方法:

def transitions
  transitions_data = []
  Transition.all.each do |transition|
    transitions_data << { transition.from.to_sym => transition.to.to_sym, :on => transition.on.to_sym }  
  end
  transitions_data
end

Obviously if you have more than one machine you can have some other column like 'machine_name' and store the machine name there and fetch only those rows.显然,如果你有不止一台机器,你可以有一些其他的列,比如“machine_name”,并将机器名称存储在那里,只获取那些行。

As the original person who answered this said "This is just one example, and could be much further optimized. I'll leave that part to you. Hopefully this will give you a good start."正如回答这个问题的原始人所说的“这只是一个例子,还可以进一步优化。我会把那部分留给你。希望这会给你一个好的开始。”

I hope this points you in the correct direction.我希望这为您指明了正确的方向。

Source:来源:

SO and state_machine Gem SOstate_machine Gem

rails_workflow gem is not about states :) rails_workflow gem 与状态无关:)

Most state transition engines uses states to simulate process configuration which is wrong by nature.大多数状态转换引擎使用状态来模拟本质上是错误的过程配置。 If some application have process (meaning business logic process with different operations, user operations, tasks etc) - then it should use process management and most of gems with states-to-states transition uses state transitions just to roughly simulate workflow.如果某些应用程序有流程(意味着具有不同操作、用户操作、任务等的业务逻辑流程) - 那么它应该使用流程管理,并且大多数具有状态到状态转换的 gem 使用状态转换只是为了粗略地模拟工作流。

There is lots of disadvantages of states transition logic so again - rails_workflow is not about states :) It's about process configuration, monitoring and controlling.状态转换逻辑有很多缺点 - rails_workflow 与状态无关:) 它与过程配置、监视和控制有关。

You can copy redmine , or build your own service object with ease using this gem :您可以复制 redmine ,或使用此 gem 轻松构建自己的服务对象:

Waterfall瀑布

It's a brand new gem , i met his author in RubyLille this week.这是一个全新的宝石,我本周在 RubyLille 遇到了他的作者。 it'a way to elegantly chain callback-like methods and get errors managed by rails , you can build a robust state machine with this .这是一种优雅地链接类回调方法并获取由 rails 管理的错误的方法,您可以使用它构建一个健壮的状态机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM