On Thu, Jul 08, 2010 at 01:22:36AM -0700, Don French wrote:
>
> I am looking at ways to put processes in ruby classes. The approach I
> am thinking about is:
> 
> module Processes
>   class TestProcess
> 
>     def initialize(value)
>       @pdef = Route.process_definition :name => 'test' do
>         sequence do
>           result = some_method(value)  # this could be outside the
> process definition
>           set :field => 'value' => value
>           participant :process_value_participant
>           participant :finish_with_value
>         end
>     end
> 
>     def process
>       @pdef
>     end
> 
>     def some_method(value)
>       value
>     end
>   end
> end
> 
> Does this make sense? or is there a better way.

Hello Don,

it seems you want to create some kind of [process definition] generation. I'd 
recommend something like :

---8<---
module Processes

  class TestProcess

    def initialize (initial_values)
      @iv = initial_values
    end

    def generate (values={})

      values = @iv.merge(values)

      Ruote.process_definition :name => 'test' do
        sequence do
          set 'f:value' => values['value']
          participant :process_value_participant
          participant :finish_with_value
        end
      end
    end

    def launch (engine, values={})

      engine.launch(generate(values))
    end
  end
end

tp = Processes::TestProcess.new('value' => 'initial')
tp.launch(engine)
tp.launch(engine, 'value' => 'overriden')
--->8---

Please note that if you only need to set initial values for the workitem 
fields, you can go with

---8<---
pdef = Ruote.process_definition :name => 'test' do
  sequence do
    participant :process_value_participant
    participant :finish_with_value
  end
end

engine.launch(pdef, 'value' => 'my first value')
engine.launch(pdef, 'value' => 'my other value', 'sum' => 5)
--->8---

These two examples can be extended and refined.


Best regards,

-- 
John Mettraux - http://jmettraux.wordpress.com

-- 
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en

Reply via email to