summaryrefslogtreecommitdiff
path: root/lib/custodian/testfactory.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-02-17 20:49:37 +0000
committerSteve Kemp <steve@steve.org.uk>2015-02-17 20:49:37 +0000
commit35276b1d16affa1e19c4e05cca237c74cee2205e (patch)
tree76b822959e5114f9566a185ba0a85b8bf8e70101 /lib/custodian/testfactory.rb
parenta9063becb31ffd23aa3c1e759565217e0755bc9b (diff)
Allow multiple handlers to register themselves for
a given input-line.
Diffstat (limited to 'lib/custodian/testfactory.rb')
-rw-r--r--lib/custodian/testfactory.rb62
1 files changed, 42 insertions, 20 deletions
diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb
index 603b69f..b00703f 100644
--- a/lib/custodian/testfactory.rb
+++ b/lib/custodian/testfactory.rb
@@ -36,29 +36,45 @@ module Custodian
raise ArgumentError, "The type of test to create must be a string" unless ( line.kind_of? String )
#
+ # The array we return.
+ #
+ result = Array.new()
+
+
+ #
# If this is an obvious protocol test.
#
if ( line =~ /must\s+(not\s+)?run\s+(\S+)(\s+|\.|$)/ )
+
test_type = $2.dup
test_type.chomp!( "." )
- c = @@subclasses[test_type]
- if c
-
- obj = c.new( line )
-
- #
- # Get the notification text, which is not specific to the test-type
- #
- # We do this only after we've instantiated the test.
- #
- if ( line =~ /\s+otherwise\s+'([^']+)'/ )
- obj.set_notification_text( $1.dup )
- end
- return obj
- else
- raise ArgumentError, "Bad test type: '#{test_type}'"
+ #
+ # For each of the test-classes that implement the type
+ #
+ @@subclasses[test_type].each do |impl|
+
+ if impl
+ obj = impl.new( line )
+
+ #
+ # Get the notification text, which is not specific to the test-type
+ #
+ # We do this only after we've instantiated the test.
+ #
+ if ( line =~ /\s+otherwise\s+'([^']+)'/ )
+ obj.set_notification_text( $1.dup )
+ end
+
+ result.push(obj)
+ else
+ raise ArgumentError, "Bad test type: '#{test_type}'"
+ end
end
+
+ # return the test-types.
+ return( result )
+
else
raise "Unknown line given - Failed to instantiate a suitable protocol-test: '#{line}'"
end
@@ -69,7 +85,8 @@ module Custodian
# Register a new test type - this must be called by our derived classes
#
def self.register_test_type name
- @@subclasses[name] = self
+ @@subclasses[name] ||= Array.new()
+ @@subclasses[name].push(self)
end
@@ -88,9 +105,14 @@ module Custodian
# Get the friendly-type of this class
#
def get_type
- @@subclasses.each do |name,value|
- if ( value == self.class )
- return name
+ # get each registed type
+ @@subclasses.keys.each do |name|
+
+ # for each handler ..
+ @@subclasses[name].each do |impl|
+ if ( impl == self.class )
+ return name
+ end
end
end
nil