Class: Ruote::Exp::IfExpression
- Inherits:
-
FlowExpression
- Object
- FlowExpression
- Ruote::Exp::IfExpression
- Defined in:
- lib/ruote/exp/fe_if.rb
Overview
Here are examples of the ‘if’ expression in use :
_if do
equals :field_value => 'customer', :other_value => 'British Petroleum'
participant :ref => 'Allister'
end
and :
_if :test => '${f:customer} == British Petroleum' do
participant :ref => 'Allister'
end
An else clause is accepted :
_if do
equals :field_value => 'customer', :other_value => 'British Petroleum'
participant :ref => 'Allister'
participant :ref => 'Bernardo'
end
or :
_if :test => '${f:customer} == British Petroleum' do
participant :ref => 'Allister'
participant :ref => 'Bernardo'
end
Note that any expression accepts an :if attribute :
participant :ref => 'Al', :if => '${f:customer} == British Petroleum'
shorter
The :test can be shortened to a :t :
_if :t => '${f:customer.name} == Fred' do
subprocess 'premium_course'
subprocess 'regular_course'
end
When using Ruby to generate the process definition tree, you can simply do :
_if '${f:customer.name} == Fred' do
subprocess 'premium_course'
subprocess 'regular_course'
end
Constant Summary
Constants inherited from FlowExpression
FlowExpression::COMMON_ATT_KEYS
Instance Attribute Summary
Attributes inherited from FlowExpression
Instance Method Summary collapse
- #apply ⇒ Object
-
#reply(workitem) ⇒ Object
called by ‘else’, ‘then’ or perhaps ‘equals’.
Methods inherited from FlowExpression
#ancestor?, #att, #attribute, #attribute_text, #attributes, #cancel, #compile_atts, #compile_variables, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_resume, #do_unpersist, #expand_atts, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #iterative_var_lookup, #launch_sub, #lookup_on_error, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #persist_or_raise, #reply_to_parent, #set_variable, #to_h, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables
Methods included from WithMeta
Methods included from WithH
Constructor Details
This class inherits a constructor from Ruote::Exp::FlowExpression
Instance Method Details
#apply ⇒ Object
82 83 84 85 |
# File 'lib/ruote/exp/fe_if.rb', line 82 def apply reply(h.applied_workitem) end |
#reply(workitem) ⇒ Object
called by ‘else’, ‘then’ or perhaps ‘equals’
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ruote/exp/fe_if.rb', line 89 def reply(workitem) if workitem['fei'] == h.fei # apply --> reply h.test = attribute(:test) h.test = attribute(:t) if h.test.nil? h.test = attribute_text if h.test.nil? h.test = nil if h.test == '' offset = (h.test.nil? || Condition.true?(h.test)) ? 0 : 1 apply_child(offset, workitem) else # reply from a child if h.test != nil || Ruote::FlowExpressionId.child_id(workitem['fei']) != 0 reply_to_parent(workitem) else apply_child(workitem['fields']['__result__'] == true ? 1 : 2, workitem) end end end |