Class: NagiosHerald::Message
- Inherits:
-
Object
- Object
- NagiosHerald::Message
- Defined in:
- lib/nagios-herald/messages/irc.rb,
lib/nagios-herald/messages/base.rb,
lib/nagios-herald/messages/email.rb,
lib/nagios-herald/messages/pager.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Public: When subclassed message types are instantiated, add them to the @@message_types hash.
- .message_types ⇒ Object
Instance Method Summary collapse
-
#initialize(recipients, options) ⇒ Message
constructor
A new instance of Message.
-
#send ⇒ Object
Public: Defines what is required to send a message.
Methods included from Util
#get_nagios_var, get_script_path, load_helper, underscore_to_camel_case, #unescape_text
Methods included from Logging
#configure_logger_for, #logger, #logger_for
Constructor Details
#initialize(recipients, options) ⇒ Message
Returns a new instance of Message.
16 17 18 19 20 |
# File 'lib/nagios-herald/messages/base.rb', line 16 def initialize(recipients, ) @no_send = [:no_send] # TODO: instead of passing this in via the subclass, let's set it via message.recipients @recipients = recipients end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
13 14 15 |
# File 'lib/nagios-herald/messages/base.rb', line 13 def content @content end |
#recipients ⇒ Object
Returns the value of attribute recipients.
14 15 16 |
# File 'lib/nagios-herald/messages/base.rb', line 14 def recipients @recipients end |
Class Method Details
.inherited(subclass) ⇒ Object
Public: When subclassed message types are instantiated, add them to the @@message_types hash. The key is the downcased and snake_cased name of the class file (i.e. email); the value is the actual class (i.e. Email) so that we can easily instantiate message types when we know the message type name. Learned this pattern thanks to the folks at Chef and @jonlives. See github.com/opscode/chef/blob/11-stable/lib/chef/knife.rb#L79#L83
Returns the message_types hash.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nagios-herald/messages/base.rb', line 41 def self.inherited(subclass) subclass_base_name = subclass.name.split('::').last if subclass_base_name == subclass_base_name.upcase # we've got an all upper case class name (probably an acronym like IRC); just downcase the whole thing subclass_base_name.downcase! [subclass_base_name] = subclass else subclass_base_name.gsub!(/[A-Z]/) { |s| "_" + s } # replace uppercase with underscore and lowercase subclass_base_name.downcase! subclass_base_name.sub!(/^_/, "") # strip the leading underscore [subclass_base_name] = subclass end end |
.message_types ⇒ Object
29 30 31 |
# File 'lib/nagios-herald/messages/base.rb', line 29 def self. @@message_types ||= {} end |
Instance Method Details
#send ⇒ Object
Public: Defines what is required to send a message. The message type knows best how this is done. Override the #send method in your message subclass.
25 26 27 |
# File 'lib/nagios-herald/messages/base.rb', line 25 def send raise Exception, "#{self.to_s}: You must override #send" end |