lib/openwfe/participants/participantmap.rb in openwferu-0.9.16 vs lib/openwfe/participants/participantmap.rb in openwferu-0.9.17
- old
+ new
@@ -1,8 +1,8 @@
#
#--
-# Copyright (c) 2006-2007, John Mettraux, OpenWFE.org
+# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
@@ -40,23 +40,22 @@
require 'openwfe/workitem'
require 'openwfe/service'
require 'openwfe/util/observable'
require 'openwfe/participants/participants'
-include OpenWFE
+#include OpenWFE
module OpenWFE
#
# A very simple directory of participants
#
class ParticipantMap < Service
include OwfeObservable
- attr_accessor \
- :participants
+ attr_accessor :participants
def initialize (service_name, application_context)
super
@@ -75,14 +74,23 @@
#
# Adds a participant to this map.
# This method is called by the engine's own register_participant()
# method.
#
- # The participant instance is returned by this method call
+ # The participant instance is returned by this method call.
#
- def register_participant (regex, participant=nil, &block)
+ # The know params are :participant (a participant instance or
+ # class) and :position (which can be null or :first).
+ #
+ # By default (if :position is not set to :first), the participant
+ # will appear at the bottom of the participant list.
+ #
+ def register_participant (regex, params, &block)
+ participant = params[:participant]
+ position = params[:position]
+
if not participant
raise "please provide a participant instance or a block" \
if not block
@@ -92,11 +100,11 @@
ldebug do
"register_participant() "+
"participant class is #{participant.class}"
end
- if participant.kind_of?(Class)
+ if participant.is_a?(Class)
ldebug { "register_participant() class #{participant}" }
begin
@@ -130,14 +138,20 @@
attr_reader :original_string
end
regex.instance_variable_set '@original_string', original_string
participant.application_context = @application_context \
- if participant.respond_to? :application_context=
+ if participant.respond_to?(:application_context=)
- @participants << [ regex, participant ]
+ # now add the participant to the list
+ entry = [ regex, participant ]
+
+ index = (position == :first) ? 0 : -1
+
+ @participants.insert index, entry
+
participant
end
#
# Looks up a participant given a participant_name.
@@ -194,10 +208,10 @@
onotify :dispatch, :before_consume, workitem
workitem.dispatch_time = Time.now
- participant.consume(workitem)
+ participant.consume workitem
onotify :dispatch, :after_consume, workitem
end
#