nested states

30 views
Skip to first unread message

Bill Burcham

unread,
Jan 1, 2013, 3:24:31 PM1/1/13
to pluginaw...@googlegroups.com
I have "succeeded" and "failed" states that both represent "completed" states. The traditional way to represent that in a state transition diagram is with nested states: "succeeded" and "failed" nest under "completed". This might introduce the notion of multiple simultaneous states e.g. "failed"/"completed", "succeeded"/"completed".

The way I am handling this now is by explicitly modeling the compound state and synthesizing a predicate for it (completed?):

complete_states = [:succeeded, :failed]

state_machine do

  state all - complete_states do
    def complete?
      false
    end
  end

  state *complete_states do
    def complete?
      true
    end
  end

  after_transition any => complete_states do
     do_stuff!
  end
  ...

The predicate method pair is a bit not-DRY but perhaps worse is that my (graphviz) diagram doesn't nest "succeeded"/"failed" under "completed".

Am I doing this right or is there a better way with state_machine?

Bill Burcham

unread,
Jan 4, 2013, 2:57:54 AM1/4/13
to pluginaw...@googlegroups.com
BTW the project where I'm doing the "nested states" is called orchestrated. It's a lightweight workflow orchestration gem that runs atop delayed_job.

Github: (docs including Graphviz output of states) https://github.com/paydici/orchestrated
Reply all
Reply to author
Forward
0 new messages