lib/openwfe/participants/participants.rb in openwferu-0.9.15 vs lib/openwfe/participants/participants.rb in openwferu-0.9.16

- old
+ new

@@ -38,10 +38,11 @@ # require 'yaml' require 'openwfe/utils' +require 'openwfe/util/dollar' require 'openwfe/participants/participant' # # some base participant implementations @@ -167,11 +168,12 @@ def consume (workitem) result = call_block @block, workitem - workitem.set_result(result) if result + workitem.set_result(result) \ + if result and result != workitem reply_to_engine(workitem) \ if workitem.kind_of? InFlowWorkItem # else it's a cancel item end @@ -223,17 +225,21 @@ # # The NoOperationParticipant immediately replies to the engine upon # receiving a workitem. # + # Is used in testing. Could also be useful during the 'development' + # phase of a business process, as an empty placeholder. + # class NoOperationParticipant include LocalParticipant # # Simply discards the incoming workitem # def consume (workitem) + reply_to_engine workitem end end # @@ -346,9 +352,48 @@ get_flow_expression(workitem), 0, #sub_id @template, workitem) #params) + end + end + + # + # This mixin provides an eval_template() method. This method assumes + # the target class has a @block_template and a @template, it also + # assumes the class includes the module LocalParticipant. + # + # This mixin is used for example in the MailParticipant class. + # + module TemplateMixin + + # + # Given a workitem, expands the template and returns it as a String. + # + def eval_template (workitem) + + fe = get_flow_expression workitem + + template = if @block_template + + call_block @block_template, workitem + + elsif @template + + template = if @template.kind_of?(File) + @template.readlines + else + @template.to_s + end + + else + + nil + end + + return "(no template given)" unless template + + OpenWFE::dosub template, fe, workitem end end end