lib/openwfe/participants/participantmap.rb in openwferu-0.9.15 vs lib/openwfe/participants/participantmap.rb in openwferu-0.9.16
- old
+ new
@@ -59,11 +59,10 @@
def initialize (service_name, application_context)
super
@participants = []
-
@observers = {}
end
#
# Returns how many participants are currently registered here.
@@ -85,19 +84,19 @@
if not participant
raise "please provide a participant instance or a block" \
if not block
- participant = BlockParticipant.new(block)
+ participant = BlockParticipant.new block
end
ldebug do
"register_participant() "+
"participant class is #{participant.class}"
end
- if participant.kind_of? Class
+ if participant.kind_of?(Class)
ldebug { "register_participant() class #{participant}" }
begin
@@ -112,20 +111,27 @@
participant = participant.new
end
end
- unless regex.kind_of? Regexp
+ original_string = regex.to_s
+ unless regex.kind_of?(Regexp)
+
regex = regex.to_s
regex = "^" + regex unless regex[0, 1] == "^"
regex = regex + "$" unless regex[-1, 1] == "$"
ldebug { "register_participant() '#{regex}'" }
regex = Regexp.new(regex)
end
+
+ class << regex
+ attr_reader :original_string
+ end
+ regex.instance_variable_set '@original_string', original_string
participant.application_context = @application_context \
if participant.respond_to? :application_context=
@participants << [ regex, participant ]
@@ -153,19 +159,17 @@
#
# Deletes the first participant matching the given name.
#
def unregister_participant (participant_name)
- pos = -1
- @participants.each_with_index do |tuple, index|
- if tuple[0].match(participant_name)
- pos = index
- break
- end
+ participant_name = participant_name.to_s
+
+ p = @participants.find do |tuple|
+ tuple[0].original_string == participant_name
end
- @participants.delete(pos) if pos > -1
+ @participants.delete(p) if p
- pos > -1
+ (p != nil)
end
#
# Dispatches to the given participant (participant name (string) or
# The workitem will be fed to the consume() method of that participant.