Class: Ruote::Exp::ThatExpression

Inherits:
SequenceExpression show all
Defined in:
lib/ruote/exp/fe_that.rb

Overview

The 'that' and the 'of' expressions are used in conjuction with the 'given' expression (GivenExpression).

In can be used 'standalone', it thus becomes then merely an 'if'.

The children of the that/of are executed if the condition evaluates to true. The children are executed one by one, as if the that/of were a sequence.

given '${status}' do
  that '${location} == CH' do
    set 'f:bank' => 'UBS'
    subprocess 'buy_chocolate'
  end
  of 'ready' do
    participant 'saleshead', :msg => 'customer ready'
    participant 'salesman', :task => 'visiter customer'
  end
  of 'over' do
    participant 'manager', :msg => 'process over'
  end
end

(Yes, I know, it's a poor example).

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error

Instance Method Summary collapse

Methods inherited from SequenceExpression

#apply

Methods inherited from FlowExpression

#ancestor?, #applied_workitem, #att, #att_text, #attribute, #attribute_text, #attributes, #await, #cancel, #cancel_flanks, #cfei_at, #child_id, #child_ids, #compile_atts, #compile_variables, #debug_id, #deflate, #do, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_reply_to_parent, #do_resume, #do_unpersist, dummy, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #is_concurrent?, #iterative_var_lookup, #launch_sub, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #pause_on_apply, #persist_or_raise, #root, #root_id, #set_variable, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables, #wfid

Methods included from WithMeta

#class_def, included

Methods included from WithH

#h, #h=, included, #to_h

Constructor Details

This class inherits a constructor from Ruote::Exp::FlowExpression

Instance Method Details

#reply(workitem) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ruote/exp/fe_that.rb', line 60

def reply(workitem)

  if workitem['fei'] == h.fei # apply --> reply

    cond = attribute(:t) || attribute(:test) || attribute_text

    if name == 'of'
      comparator = cond.match(/^\s*\/.*\/\s*$/) ? '=~' : '=='
      cond = "#{workitem['fields']['__given__']} #{comparator} #{cond}"
    end

    h.result = Condition.true?(cond)

    if h.result
      apply_child(0, workitem)
    else
      reply_to_parent(workitem)
    end

  else # reply from child

    super
  end
end

#reply_to_parent(workitem) ⇒ Object


85
86
87
88
89
# File 'lib/ruote/exp/fe_that.rb', line 85

def reply_to_parent(workitem)

  workitem['fields']['__result__'] = h.result
  super
end