Class: NagiosHerald::MessageLoader

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/nagios-herald/message_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#configure_logger_for, #logger, #logger_for

Constructor Details

#initializeMessageLoader

Returns a new instance of MessageLoader.



8
9
10
11
# File 'lib/nagios-herald/message_loader.rb', line 8

def initialize
  # TODO: add support for @options.message_path
  @message_path = File.expand_path("messages", File.dirname(__FILE__))
end

Instance Attribute Details

#message_pathObject

Returns the value of attribute message_path.



6
7
8
# File 'lib/nagios-herald/message_loader.rb', line 6

def message_path
  @message_path
end

Instance Method Details

#enum_message_class_files(message_path) ⇒ Object

Public: Enumerate the available message class files.

Returns an array of the class files’ absolute paths



16
17
18
# File 'lib/nagios-herald/message_loader.rb', line 16

def enum_message_class_files(message_path)
  message_class_files = Dir.glob(File.expand_path("*.rb", message_path))
end

#load_messagesObject

Public: Load the messages into the namespace. A message can then easily be instantiated later.



27
28
29
30
31
32
33
34
35
36
# File 'lib/nagios-herald/message_loader.rb', line 27

def load_messages
  if message_class_files.empty?
    logger.fatal "#{$0}: No messages were found in '#{@message_path}'"
    exit 1
  else
    message_class_files.each do |message_class_file|
      Kernel.load message_class_file
    end
  end
end

#message_class_filesObject

Public: Return an array of class files’ paths.



21
22
23
# File 'lib/nagios-herald/message_loader.rb', line 21

def message_class_files
  @message_class_files ||= enum_message_class_files(@message_path)
end