diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-22 11:13:51 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-22 11:13:51 +0000 |
commit | a00e6b8537de27da16a4ede8466233be4e1b8c8c (patch) | |
tree | 8fb428956622af9be6a8da5637757069a2ba8a12 | |
parent | e0d947b217aed5e06355ff3c9512dbcea563564c (diff) |
Moved TestFactory to the custodian-namespace.
-rwxr-xr-x | bin/custodian-parse-execute | 2 | ||||
-rw-r--r-- | lib/custodian/testfactory.rb | 106 |
2 files changed, 56 insertions, 52 deletions
diff --git a/bin/custodian-parse-execute b/bin/custodian-parse-execute index a99246e..2a75629 100755 --- a/bin/custodian-parse-execute +++ b/bin/custodian-parse-execute @@ -39,7 +39,7 @@ end # Create the object # begin - c = TestFactory.create( txt ) + c = Custodian::TestFactory.create( txt ) puts "created object of class type #{c.class}" puts ".to_s : #{c.to_s}" diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index c736ac1..5b2428d 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -13,75 +13,79 @@ require 'json' # file - or that line encoded as a JSON string. # # -class TestFactory +module Custodian - # - # The subclasses we have. - # - @@subclasses = { } + class TestFactory - # - # Create a test-type object given a line of text from our parser. - # - # The line will be like "target must run tcp|ssh|ftp|smtp .." - # - # - def self.create( line ) - # - # JSON ? + # The subclasses we have. # - if ( line =~ /^\{(.*)\}$/ ) - begin - obj = JSON.parse( line ); - raise ArgumentError, "JSON object was not a hash" unless obj.kind_of?(Hash) - line = obj["line"] - raise ArgumentError, "obj[:line] was nil" unless (!line.nil?) - rescue =>ex - raise ArgumentError, "Line did not deserialize from JSON: #{line} - #{ex}" - end - end + @@subclasses = { } # - # If this is an obvious protocol test. + # Create a test-type object given a line of text from our parser. # - if ( line =~ /must\s+run\s+(\S+)(\s+|\.|$)/ ) - test_type = $1.dup - test_type.chomp!( "." ) + # The line will be like "target must run tcp|ssh|ftp|smtp .." + # + # + def self.create( line ) + + # + # JSON ? + # + if ( line =~ /^\{(.*)\}$/ ) + begin + obj = JSON.parse( line ); + raise ArgumentError, "JSON object was not a hash" unless obj.kind_of?(Hash) + line = obj["line"] + raise ArgumentError, "obj[:line] was nil" unless (!line.nil?) + rescue =>ex + raise ArgumentError, "Line did not deserialize from JSON: #{line} - #{ex}" + end + end - c = @@subclasses[test_type] - if c - c.new( line ) + + # + # If this is an obvious protocol test. + # + if ( line =~ /must\s+run\s+(\S+)(\s+|\.|$)/ ) + test_type = $1.dup + test_type.chomp!( "." ) + + c = @@subclasses[test_type] + if c + c.new( line ) + else + raise ArgumentError, "Bad test type: #{test_type}" + end else - raise ArgumentError, "Bad test type: #{test_type}" + raise "Unknown line given - Failed to instantiate a suitable protocol-test." end - else - raise "Unknown line given - Failed to instantiate a suitable protocol-test." end - end - # - # Register a new test type - this must be called by our derived classes - # - def self.register_test_type name - @@subclasses[name] = self - end + # + # Register a new test type - this must be called by our derived classes + # + def self.register_test_type name + @@subclasses[name] = self + end - # - # Return an array of test-types we know about - # - # i.e. Derived classes that have registered themselves. - # - # - def types - @@subclasses - end + # + # Return an array of test-types we know about + # + # i.e. Derived classes that have registered themselves. + # + # + def types + @@subclasses + end -end + end +end |