Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 274
General Failure Avatar asked Feb 07 '23 17:02

General Failure


2 Answers

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

like image 84
Jagjot Avatar answered Mar 29 '23 23:03

Jagjot


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.

like image 42
Max Avatar answered Mar 30 '23 01:03

Max