Class: Ruote::Exp::DefineExpression

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

Overview

The main names for this expression are 'define' and 'process_definition'. It simply encloses a process definition (and gives it a name and revision if needed).

pdef = Ruote.process_definition :name => 'test', :revision => '0' do
  sequence do
    participant :ref => 'alice'
    participant :ref => 'bob'
  end
end

It's used for subprocess definitions as well.

pdef = Ruote.process_definition :name => 'test', :revision => '0' do
  sequence do
    buy_food
    cook_food
  end
  define 'buy_food' do
    participant :ref => 'alice'
  end
  define :name => 'cook_food' do
    participant :ref => 'bob'
  end
end

like a sequence

Ruote 2.0 treats the child expressions of a 'define' expression like a 'sequence' expression does. Thus, this

pdef = Ruote.process_definition :name => 'test' do
  sequence do
    buy_food
    cook_food
  end
end

is equivalent to

pdef = Ruote.process_definition :name => 'test' do
  buy_food
  cook_food
end

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error

Class Method Summary collapse

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, #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

Class Method Details

.is_definition?(tree) ⇒ Boolean

Returns true if the tree's root expression is a definition (define, process_definition, …)

Returns:

  • (Boolean)

95
96
97
98
# File 'lib/ruote/exp/fe_define.rb', line 95

def self.is_definition?(tree)

  self.expression_names.include?(tree.first)
end

.reorganize(tree) ⇒ Object

Used by instances of this class and also the expression pool, when launching a new process instance.


103
104
105
106
107
108
109
110
111
# File 'lib/ruote/exp/fe_define.rb', line 103

def self.reorganize(tree)

  definitions, bodies = tree[2].partition { |b| is_definition?(b) }
  name = tree[1]['name'] || tree[1].keys.find { |k| tree[1][k] == nil }

  definitions = definitions.collect { |d| reorganize(d)[1] }

  [ name, [ 'define', tree[1], definitions + bodies ] ]
end

Instance Method Details

#applyObject


78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ruote/exp/fe_define.rb', line 78

def apply

  t = self.class.reorganize(tree).last

  name = attribute(:name) || attribute_text

  set_variable(name, [ h.fei['expid'], t ]) if name
    #
    # fei.expid : keeping track of the expid/branch for the subprocess
    #             (so that graphical representations match)

  reply_to_parent(h.applied_workitem)
end