Class: OpenWFE::CursorCommandExpression
- Inherits:
-
FlowExpression
- Object
- ObjectWithMeta
- FlowExpression
- OpenWFE::CursorCommandExpression
- Includes:
- CommandConstants, ConditionMixin
- Defined in:
- lib/openwfe/expressions/fe_command.rb
Overview
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 :
-
back : will go back from the number of given steps, 1 by default
-
break : will exit the cursor (or the loop)
-
cancel : an alias for ‘break’
-
continue : will exit the cursor, if in a loop, will get back at step 0
-
jump : will move the cursor (or loop) to an absolute given position (count starts at 0)
-
rewind : an alias for continue
-
skip : skips the given number of steps
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
Instance Attribute Summary
Attributes inherited from FlowExpression
#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation
Attributes included from Contextual
Instance Method Summary collapse
Methods included from ConditionMixin
#determine_condition_attribute, #eval_condition
Methods inherited from FlowExpression
#cancel, #clean_children, #delete_variable, #dup_environment, #fetch_environment, #fetch_text_content, #get_binding, #get_environment, #get_parent, #get_root_environment, #has_attribute, #initialize, is_definition, is_definition?, #lookup_attribute, #lookup_attributes, #lookup_boolean_attribute, #lookup_comma_list_attribute, #lookup_downcase_attribute, #lookup_ref, #lookup_string_attribute, #lookup_sym_attribute, #lookup_value, #lookup_variable, #lookup_vf_attribute, names, #new_environment, new_exp, #owns_its_environment?, #paused?, #remove_child, #reply, #reply_to_parent, #set_variable, #store_itself, #synchronize, #to_s, #to_yaml_properties
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Methods included from OwfeServiceLocator
#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator
Methods inherited from ObjectWithMeta
#class_def, meta_def, meta_eval, metaclass
Constructor Details
This class inherits a constructor from OpenWFE::FlowExpression
Instance Method Details
#apply(workitem) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/openwfe/expressions/fe_command.rb', line 216 def apply (workitem) conditional = eval_condition(:if, workitem, :unless) # # for example : <break if="${approved} == true"/> if conditional == nil or conditional command = @fei.expression_name step = lookup_attribute(A_STEP, workitem) step = fetch_text_content(workitem) unless step step = 1 unless step step = Integer(step) command = "#{command} #{step}" #if step != 1 workitem.attributes[F_COMMAND] = command end reply_to_parent workitem end |