diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-24 14:40:03 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-24 14:40:03 +0000 |
commit | 1846a7188b0fa58c8ecc50d12573af92bf2fb39e (patch) | |
tree | 2ffeab10f8e977063bb003924ea27ac34b74cdd3 /lib/custodian/alertfactory.rb | |
parent | ed4e49422719f5e7b932da3ae1be9ed26a052466 (diff) |
Initial/stub implementation of a factory for generating alerting objects.
Diffstat (limited to 'lib/custodian/alertfactory.rb')
-rw-r--r-- | lib/custodian/alertfactory.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/custodian/alertfactory.rb b/lib/custodian/alertfactory.rb new file mode 100644 index 0000000..f82706f --- /dev/null +++ b/lib/custodian/alertfactory.rb @@ -0,0 +1,70 @@ + + +# +# +# Base class for custodian alerters. +# +# Each subclass will register themselves, via the call +# to 'register_alert_type'. +# +# This class is a factory that will return the correct +# derived class. +# +# +module Custodian + + class AlertFactory + + + # + # The subclasses we have. + # + @@subclasses = { } + + + # + # Create an alerter object, based upon the type + # + def self.create( alert_type, obj ) + + c = @@subclasses[alert_type] + if c + c.new( obj ) + else + raise ArgumentError, "Bad alert type: '#{alert_type}'" + end + end + + + # + # Register a new test type - this must be called by our derived classes + # + def self.register_alert_type name + @@subclasses[name] = self + end + + + # + # Return an array of test-types we know about + # + # i.e. Derived classes that have registered themselves. + # + # + def self.known_alerters + @@subclasses + end + + + + def raise + raise NoMethod, "This should be implemented in a derived class" + end + + + + def clear + raise NoMethod, "This should be implemented in a derived class" + end + end + +end |