简体   繁体   中英

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.

I found some gems: rails_workflow , state_machine , workflow .

But as I understood, these gems assumes that states will be hard-coded, eg workflow gem states:

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

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:

Define a Transition model with columns, 'to', 'from' and 'on'. They all will have string as their data-type.

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.

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

rails_workflow gem is not about states :)

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.

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.

You can copy redmine , or build your own service object with ease using this gem :

Waterfall

It's a brand new gem , i met his author in RubyLille this week. it'a way to elegantly chain callback-like methods and get errors managed by rails , you can build a robust state machine with this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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