| Class | OpenWFE::CursorCommandExpression |
| In: |
lib/openwfe/expressions/fe_command.rb
|
| Parent: | FlowExpression |
This class implements the following expressions : back, break, cancel, continue, jump, rewind, skip.
They are generally used inside of a ‘cursor’ (CursorExpression) or a ‘loop’ (LoopExpression), they can be used outside, but their result (the value of the field ‘__cursor_command__’ will be used as soon as the flow enters a cursor or a loop).
In fact, this expression is only a nice wrapper that sets the value of the field "__cursor_command__" to its name (‘back’ for example) plus to the ‘step’ attribute value.
For example <skip step="3"/> simply sets the value of the field ‘__cursor_command__’ to ‘skip 3’.
(The field __cursor_command__ is, by default, read and obeyed by the ‘cursor’ expression).
With Ruby process definitions, you can directly write :
skip 2
jump "0"
instead of
skip :step => "2"
jump :step => "0"
Likewise, in an XML process definition, you can write
<skip>2</skip>
although that might still look lighter (it‘s longer though) :
<skip step="2"/>
About the command themselves :
All those command support an ‘if’ attribute to restrict their execution :
cursor do
go_to_shop
check_prices
_break :if => "${price} > ${f:current_cash}"
buy_stuff
end
The ‘rif’ attribute may be used instead of the ‘if’ attribute. Its value is some ruby code that, when evaluating to true will let the command be executed.
_skip 2, :rif => "workitem.customers.size % 2 == 0"
#
# skips if the nb of customers is pair
Note that the ‘rif’ attribute will work only if the :ruby_eval_allowed parameter is set to true in the engine‘s application context.
engine.application_context[:ruby_eval_allowed] = true
# File lib/openwfe/expressions/fe_command.rb, line 216
216: def apply (workitem)
217:
218: conditional = eval_condition(:if, workitem, :unless)
219: #
220: # for example : <break if="${approved} == true"/>
221:
222: if conditional == nil or conditional
223:
224: command = @fei.expression_name
225:
226: step = lookup_attribute(A_STEP, workitem)
227: step = fetch_text_content(workitem) unless step
228: step = 1 unless step
229: step = Integer(step)
230:
231: command = "#{command} #{step}" #if step != 1
232:
233: workitem.attributes[F_COMMAND] = command
234: end
235:
236: reply_to_parent workitem
237: end