2015-06-27 103 views
0

我們在我們的Rails應用中使用geekq的workflowgem。現在我們需要處理工作流可能以不同方式結束的情況。以下是一個示例:如何在一個Rails模型中處理多個工作流?

purchase order的正常工作流程可能是issue PO=>receive delivery at front desk=>receive into production warehouse。對於生產項目和非生產性項目,有2個工作流程:

production item#: issue PO=>receive delivery at front desk=>receive into production warehouse 
non-production item#: issue PO=>receive delivery at front desk 

我們的問題是:

1. is workflow capable to handle workflow for production and non-production items? 
2. If the answer is yes, how to nicely handle different workflows? 

任何幫助表示讚賞!

回答

0

在geekq /工作流程spec,這裏是一個有關條件事件過渡部分,其提供了這裏的溶液:

Conditions are procs or lambdas added to events, like so: 

state :off 
    event :turn_on, :transition_to => :on, 
        :if => proc { |device| device.battery_level > 0 } 
    event :turn_on, :transition_to => :low_battery, 
        :if => proc { |device| device.battery_level > 10 } 
end 

When calling a device.can_<fire_event>? check, or attempting a device.<event>!, each event is checked in turn: 

    With no :if check, proceed as usual. 
    If an :if check is present, proceed if it evaluates to true, or drop to the next event. 
    If you've run out of events to check (eg. battery_level == 0), then the transition isn't possible. 
相關問題