Class: Ruote::Exp::CommandExpression

Inherits:
FlowExpression show all
Includes:
CommandMixin
Defined in:
lib/ruote/exp/fe_command.rb

Overview

This class gathers the ‘skip’, ‘back’, ‘jump’, ‘rewind’, ‘continue’, ‘reset’ and ‘break’ expressions which are used inside of the ‘cursor’ and ‘repeat’ (loop) expressions.

Look at the ‘cursor’ expression Ruote::Exp::Cursor for a discussion of each of those [sub]expressions.

The expression that understand commands are ‘cursor’, ‘repeat’ (‘loop’) and ‘iterator’. ‘concurrent_iterator’ does not understand commands since it fires all its branches when applied.

:ref => ‘tag’

It’s OK to tag a cursor/loop/iterator with the :tag attribute and then point a command to it via :ref :

concurrence do

  cursor :tag => 'main' do
    author
    editor
    publisher
  end

  # meanwhile ...

  sequence do
    sponsor
    rewind :ref => 'main', :if => '${f:stop}'
  end
end

This :ref technique may also be used with nested cursor/loop/iterator constructs :

cursor :tag => 'main' do
  cursor do
    author
    editor
    rewind :if => '${f:not_ok}'
    _break :ref => 'main', :if => '${f:abort_everything}'
  end
  head_of_edition
  rewind :if => '${f:not_ok}'
  publisher
end

this example features two nested cursors. There is a “_break” in the inner cursor, but it will break the main ‘cursor’ (and thus break the whole review process).

:ref works with the ‘iterator’ expression as well.

Constant Summary collapse

REGEXP =

Used by FlowExpression when dealing with :on_error or :on_timeout

Regexp.new("^(#{expression_names.join('|')})( .+)?$")

Constants included from CommandMixin

Ruote::Exp::CommandMixin::ATT_COMMANDS, Ruote::Exp::CommandMixin::F_COMMAND

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



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
# File 'lib/ruote/exp/fe_command.rb', line 96

def apply

  param = case name
    when 'skip', 'back' then attribute(:step) || attribute_text
    when 'jump' then attribute(:to) || attribute_text
    else nil
  end

  param = Integer(param) rescue param

  command_workitem = Ruote.fulldup(h.applied_workitem)

  set_command(command_workitem, name, param)

  target = parent
  ancestor = true

  if ref = attribute(:ref)

    fei = lookup_variable(ref)

    target = Ruote.is_a_fei?(fei) ?
      Ruote::Exp::FlowExpression.fetch(@context, fei) : nil
    target = target.is_a?(Ruote::Exp::CommandedExpression) ?
      target : nil

    ancestor = target ? ancestor?(target.h.fei) : false

  else

    target = fetch_command_target
  end

  return reply_to_parent(h.applied_workitem) if target.nil?
  return reply_to_parent(command_workitem) if target.h.fei == h.parent_id

  @context.storage.put_msg(
    'reply',
    'fei' => target.h.fei,
    'workitem' => command_workitem,
    'command' => [ name, param ]) # purely indicative for now

  reply_to_parent(h.applied_workitem) unless ancestor
end