| Class | OpenWFE::IteratorExpression |
| In: |
lib/openwfe/expressions/fe_iterator.rb
|
| Parent: | WithTemplateExpression |
The ‘iterator’ expression can be used like that for example :
<iterator
on-value="alice, bob, charles"
to-variable="user-name"
>
<set
field="${user-name} comment"
value="(please fill this field)"
/>
</iterator>
Within the iteration, the workitem field "__ic__" contains the number of elements in the iteration and the field "__ip__" the index of the current iteration.
The ‘iterator’ expression understands the same cursor commands as the CursorExpression. One can thus exit an iterator or skip steps in it.
iterator :on_value => "alice, bob, charles, doug", to_variable => "v" do
sequence do
participant :variable_ref => "v"
skip 1, :if => "${f:reply} == 'skip next'"
end
end
For more information about those commands, see CursorCommandExpression.
| iterator | [RW] | an Iterator instance that holds the list of values being iterated upon. |
# File lib/openwfe/expressions/fe_iterator.rb, line 87
87: def apply (workitem)
88:
89: if @children.length < 1
90: reply_to_parent workitem
91: return
92: end
93:
94: @iterator = Iterator.new(self, workitem)
95:
96: if @iterator.size < 1
97: reply_to_parent workitem
98: return
99: end
100:
101: reply workitem
102: end
# File lib/openwfe/expressions/fe_iterator.rb, line 104
104: def reply (workitem)
105:
106: command, step = determine_command_and_step workitem
107:
108: vars = if not command
109:
110: @iterator.next workitem
111:
112: elsif command == C_BREAK or command == C_CANCEL
113:
114: nil
115:
116: elsif command == C_REWIND or command == C_CONTINUE
117:
118: @iterator.rewind workitem
119:
120: elsif command.match "^#{C_JUMP}"
121:
122: @iterator.jump workitem, step
123:
124: else # C_SKIP or C_BACK
125:
126: @iterator.skip workitem, step
127: end
128:
129: unless vars
130: reply_to_parent workitem
131: return
132: end
133:
134: store_itself
135:
136: get_expression_pool.launch_template(
137: self, nil, @iterator.index, @children[0], workitem, vars)
138: end