Class: OpenWFE::IfExpression
- Inherits:
-
FlowExpression
- Object
- ObjectWithMeta
- FlowExpression
- OpenWFE::IfExpression
- Includes:
- ConditionMixin
- Defined in:
- lib/openwfe/expressions/fe_if.rb
Overview
The ‘if’ expression.
<if>
<equals field-value="f0" other-value="true" />
<participant ref="alpha" />
</if>
It accepts an ‘else’ clause :
<if>
<equals field-value="f0" other-value="true" />
<participant ref="alpha" />
<participant ref="bravo" />
</if>
The ‘test’ attribute can be used instead of a condition child :
<if test="${f:f0}">
<participant ref="alpha" />
</if>
The ‘rtest’ attribute can be used to embed a condition expressed directly in Ruby :
<if rtest="5 * 12 == 61">
<participant ref="alpha" />
</if>
(Note that ‘rtest’ may only be used if the :ruby_eval_allowed parameter has been set in the engine’s application_context :
engine.application_context[:ruby_eval_allowed] = true
but this is dangerous if the origin of the process defintions to run are not trusted)
Used alone with ‘test’ or ‘rtest’, the ‘if’ expression simply sets the the __result__ field of its workitem to the result of its attribute evaluation :
<if test="5 == 6"/>
will set the __result__ field of the workitem to ‘false’.
Instance Attribute Summary collapse
-
#condition_replied ⇒ Object
This boolean is set to true when the conditional claused has been evaluated and the ‘if’ is waiting for the consequence’s reply.
Attributes inherited from FlowExpression
#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation
Attributes included from Contextual
Instance Method Summary collapse
- #apply(workitem) ⇒ Object
- #reply(workitem) ⇒ Object
-
#reply_to_parent(workitem) ⇒ Object
This reply_to_parent takes care of cleaning all the children before replying to the parent expression, this is important because only the ‘then’ or the ‘else’ child got evaluated, the remaining one has to be cleaned out here.
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, #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 Attribute Details
#condition_replied ⇒ Object
This boolean is set to true when the conditional claused has been evaluated and the ‘if’ is waiting for the consequence’s reply.
107 108 109 |
# File 'lib/openwfe/expressions/fe_if.rb', line 107 def condition_replied @condition_replied end |
Instance Method Details
#apply(workitem) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/openwfe/expressions/fe_if.rb', line 110 def apply (workitem) #workitem.unset_result # # since OpenWFEru 0.9.16 previous __result__ values # are not erased before an 'if'. test = eval_condition(:test, workitem, :not) if @children.length < 1 #workitem.set_result test if test workitem.set_result((test != nil and test != false)) reply_to_parent(workitem) return end @condition_replied = (test != nil) # # if the "test" attribute is not used, test will be null store_itself() if test != nil apply_consequence(test, workitem, 0) else get_expression_pool.apply(@children[0], workitem) end end |
#reply(workitem) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/openwfe/expressions/fe_if.rb', line 139 def reply (workitem) return reply_to_parent(workitem) \ if @condition_replied result = workitem.attributes[FIELD_RESULT] @condition_replied = true store_itself() apply_consequence result, workitem end |
#reply_to_parent(workitem) ⇒ Object
This reply_to_parent takes care of cleaning all the children before replying to the parent expression, this is important because only the ‘then’ or the ‘else’ child got evaluated, the remaining one has to be cleaned out here.
159 160 161 162 163 |
# File 'lib/openwfe/expressions/fe_if.rb', line 159 def reply_to_parent(workitem) clean_children() super workitem end |