简体   繁体   English

使用state_machine gem的嵌套状态机的ruby类

[英]ruby class with nested state machines using state_machine gem

all I am trying to implement state machine on ActiveRecord object https://github.com/pluginaweek/state_machine gem. 我试图在ActiveRecord对象https://github.com/pluginaweek/state_machine gem上实现状态机。 But I would like to have nested state_machines. 但我想嵌套state_machines。 So far I have this simple state machine: 到目前为止,我有这个简单的状态机:

class Document < ActiveRecord::Base

  state_machine :initial => :new do
    before_transition :new => :processing, :do => :start_processing

    event :start_processing do
      transition :new => :upload_to
    end

    event :finish_processing do
      transition :processing => :ok
    end

    event :error_in_processing do
      transition :processing => :error
    end

    event :to_trash do
      transition :processing => :trash
    end
  end

But what I would like to do, is to have nested state machine which would start after transition to processing state. 但我想做的是拥有嵌套状态机,它将在转换到处理状态后启动。 This nested state machine would have states such as, uploading_to_xxx, extracting_from_yyy, pending, verifying and so on. 这个嵌套状态机将具有诸如uploaded_to_xxx,extracted_from_yyy,pending,验证等状态。 I could probably implement this using just one state machine, but I would prefer to use nested state machines. 我可能只使用一个状态机来实现它,但我更喜欢使用嵌套状态机。 I can not find any samples on web. 我在网上找不到任何样品。 Does state_machine support this use case? state_machine是否支持此用例? Or if there is other gem could you point me to it? 或者,如果还有其他宝石,你可以指点我吗? thanks 谢谢

我想你可以通过工作流gem https://github.com/geekq/workflow来完成这个任务

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

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