Class: Ruote::Exp::RefExpression

Inherits:
FlowExpression show all
Defined in:
lib/ruote/exp/fe_ref.rb

Overview

Sometimes you don’t know at ‘design time’, if you want to trigger a participant or subprocess.

Ruote.process_definition do
  sequence do
    participant 'alice'
    ref '${solver}'
    participant 'charlie'
  end
end

In this process, solver’s name could be a participant name or a subprocess name.

Subprocesses have the priority over participants.

Note: this expression is used by the worker when substituting unknown expression names with participant or subprocess refs.

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error, #h

Instance Method Summary collapse

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, #reply, #reply_to_parent, #root, #root_id, #set_variable, #to_h, #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

included

Constructor Details

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

Instance Method Details

#applyObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/ruote/exp/fe_ref.rb', line 52

def apply

  key = (attribute(:ref) || attribute_text).to_s

  if name != 'ref'
    key = name
    tree[1]['ref'] = key
  end

  key = dsub(key)
    # see test/functional/ft_62_

  key2, value = iterative_var_lookup(key)

  tree[1]['ref'] = key2 if key2
  tree[1]['original_ref'] = key if key2 != key

  unless value
    #
    # seems like it's a participant

    @h['participant'] =
      @context.plist.lookup_info(tree[1]['ref'], h.applied_workitem)

    value = key2 if ( ! @h['participant']) && (key2 != key)
  end

  new_exp_name, new_exp_class = nil

  # warning: abusing on 'then' in order to have [somehow] more readability

  if
    value.is_a?(String)
  then

    if
      @context['participant_in_variable_enabled'] &&
      value.match(/\bdef consume\(/) &&
      (Rufus::TreeChecker.parse(value) rescue false)
    then
      #
      # participant code passed

      @h['participant'] = [ 'Ruote::CodeParticipant', { 'code' => value } ]
      tree[1]['ref'] = key

    elsif klass = @context.expmap.expression_class(tree[1]['ref'])
      #
      # aliased expression

      new_exp_name = value
      new_exp_class = klass
    end

  elsif
    @context['participant_in_variable_enabled'] &&
    value.is_a?(Hash) &&
    value['on_workitem']
  then
    #
    # participant 'defined' in var

    @h['participant'] = [ 'Ruote::BlockParticipant', value ]

  elsif
    value.is_a?(Array) &&
    value.size == 2 && value.last.is_a?(Hash)
  then
    #
    # participant 'registered' in var

    @h['participant'] = value
  end

  if value == nil && @h['participant'] == nil
    #
    # unknown participant or subprocess

    @h['state'] = 'failed'
    persist_or_raise

    raise("unknown participant or subprocess '#{tree[1]['ref']}'")
  end

  new_exp_name, new_exp_class = if new_exp_name
    [ new_exp_name, new_exp_class ]
  elsif @h['participant']
    [ 'participant', Ruote::Exp::ParticipantExpression ]
  else
    [ 'subprocess', Ruote::Exp::SubprocessExpression ]
  end

  tree[0] = new_exp_name
  @h['name'] = new_exp_name

  new_exp = new_exp_class.new(@context, @h)

  #new_exp.initial_persist
    # not necessary

  new_exp.apply
end