lib/ruote/exp/fe_ref.rb in ruote-2.2.0 vs lib/ruote/exp/fe_ref.rb in ruote-2.3.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2005-2012, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -40,11 +40,11 @@
# 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
+ # Note: this expression is used by the worker when substituting unknown
# expression names with participant or subprocess refs.
#
class RefExpression < FlowExpression
names :ref
@@ -56,71 +56,101 @@
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 participant
+ # 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
- if value.is_a?(Array) && value.size == 2 && value.last.is_a?(Hash)
+ 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
- unless value || @h['participant']
+ 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 = if @h['participant']
-
- @h['participant'] = nil if @h['participant'].respond_to?(:consume)
- # instantiated participant
-
- tree[0] = 'participant'
- @h['name'] = 'participant'
- Ruote::Exp::ParticipantExpression.new(@context, @h)
+ new_exp_name, new_exp_class = if new_exp_name
+ [ new_exp_name, new_exp_class ]
+ elsif @h['participant']
+ [ 'participant', Ruote::Exp::ParticipantExpression ]
else
-
- tree[0] = 'subprocess'
- @h['name'] = 'subprocess'
- Ruote::Exp::SubprocessExpression.new(@context, @h)
+ [ 'subprocess', Ruote::Exp::SubprocessExpression ]
end
- do_schedule_timeout(attribute(:timeout)) if tree[0] == 'subprocess'
- #
- # since ref neutralizes consider_timeout because participant expressions
- # handle timeout by themselves, we have to force timeout consideration
- # for subprocess expressions
+ 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
-
- def consider_timeout
-
- # neutralized
end
end
end