How to create dynamic definitions for a state machine based on user data in a database

I'm trying to write an application that will allow users to manage workflows using the State Machine gem , but I'm not sure how to proceed by letting users define their own state machines using the State Machine gem for ruby.

The dynamic definitions in the gem documentation say that I should do this by replacing code like the one below with the given source.

   def transitions
    [
      {:parked => :idling, :on => :ignite},
      {:idling => :first_gear, :first_gear => :second_gear, :on => :shift_up}
      # ...
    ]
  end

I am not sure how to do this. how to identify transistors from a database?

+2
source share
1

transitions - , . .

, ActiveRecord.

, , . , :

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

:

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

, , .

. . , .

+6

Source: https://habr.com/ru/post/1629099/


All Articles