lib/ruote/exp/fe_concurrent_iterator.rb in ruote-2.2.0 vs lib/ruote/exp/fe_concurrent_iterator.rb in ruote-2.3.0

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2005-2012, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -62,10 +62,47 @@ # # 'concurrent_iterator' does not understand commands like # rewind/break/jump/... like 'iterator' does, since it fires all its # branches when applied. # + # == :on and arrays + # + # Given a workitem field named 'x' containing the array value + # [ 'a', 'b', 'c' ] and a workitem field 'y' containing the string 'a, b, c', + # this: + # + # concurrent_iterator :on_field => 'x', :to_f => 'xx' do + # # ... + # end + # + # is equivalent to + # + # concurrent_iterator :on => '$f:x', :to_f => 'xx' do + # # ... + # end + # + # is equivalent to + # + # concurrent_iterator :on => '${f:y}', :to_f => 'xx' do + # # ... + # end + # + # == :to_field and :to_f, :to_var and :to_v, :to + # + # Those 4 lines are equivalent: + # + # concurrent_iterator :on => [ 'ceo', 'cto' ], :to_field => 'a' do ... + # concurrent_iterator :on => [ 'ceo', 'cto' ], :to_f => 'a' do ... + # concurrent_iterator :on => [ 'ceo', 'cto' ], :to => 'f:a' do ... + # concurrent_iterator :on => [ 'ceo', 'cto' ], :to => 'a' do ... + # + # Those 3 lines are equivalent: + # + # concurrent_iterator :on => [ 'ceo', 'cto' ], :to_var => 'a' do ... + # concurrent_iterator :on => [ 'ceo', 'cto' ], :to_v => 'a' do ... + # concurrent_iterator :on => [ 'ceo', 'cto' ], :to => 'v:a' do ... + # # == :times and :branches # # Similarly to the iterator expression, the :times or the :branches attribute # may be used in stead of the 'on' attribute. # @@ -84,10 +121,32 @@ # participant 'user2' # end # end # # + # == ruote 2.3.0 and the citerator children + # + # Prior to ruote 2.3.0, the concurrent-iterator only considered one child + # expression: + # + # concurrent_iterator :times => 3 do + # participant 'al' + # participant 'bob' # 'bob' would never be reached + # end + # + # So one had to write: + # + # concurrent_iterator :times => 3 do + # sequence do + # participant 'al' + # participant 'bob' # 'bob' would never be reached + # end + # end + # + # Ruote 2.3.0 lifts that restriction. + # + # # == options # # the concurrent_iterator accepts the same options for merging as its bigger # brother, the concurrence expression. # @@ -143,33 +202,35 @@ if h.times_iterator && list.size == 1 count = (list.first.to_i rescue nil) - list = (h.list_size + 1..h.list_size + count) if count + list = (h.list_size + 0...h.list_size + count) if count end list.each do |val| h.list_size += 1 workitem = Ruote.fulldup(h.applied_workitem) - #workitem = Rufus::Json.dup(h.applied_workitem) variables = { 'ii' => h.list_size - 1 } if h.to_v variables[h.to_v] = val else #if to_f workitem['fields'][h.to_f] = val end + expid, subtree = if tree_children.size > 1 + [ h.fei['expid'], [ 'sequence', {}, tree_children ] ] + else + [ "#{h.fei['expid']}_0", tree_children[0] ] + end + launch_sub( - "#{h.fei['expid']}_0", - tree_children[0], - :workitem => workitem, - :variables => variables) + expid, subtree, :workitem => workitem, :variables => variables) end end def reply(workitem) @@ -197,23 +258,23 @@ list = determine_list return reply_to_parent(h.applied_workitem) if list.empty? h.to_v, h.to_f = determine_tos - h.to_v = 'i' if h.to_v.nil? && h.to_f.nil? + h.to_v = 'i' unless h.to_v or h.to_f h.list_size = 0 add_branches(list) persist_or_raise end # Overrides the implementation found in ConcurrenceExpression # - def expected_count + def count_list_size - h.ccount ? [ h.ccount, h.list_size ].min : h.list_size + h.list_size end end end