class TaskJuggler::Message

The Message object can store several classes of messages that the application can send out.

Attributes

id[R]
line[R]
message[R]
sourceFileInfo[RW]
type[R]

Public Class Methods

new(type, id, message, sourceFileInfo, line, data, scenario) click to toggle source

Create a new Message object. The type specifies what tpye of message this is. The following types are supported: fatal, error, warning, info and debug. id is a String that must uniquely identify the source of the Message. message is a String with the actual message. sourceLineInfo is a SourceLineInfo object that can reference a location in a specific file. line is a String of that file. data can be any context sensitive data. sceneario specifies the Scenario in which the message originated.

# File lib/taskjuggler/MessageHandler.rb, line 44
def initialize(type, id, message, sourceFileInfo, line, data, scenario)
  unless [ :fatal, :error, :warning, :info, :debug ].
         include?(type)
    raise "Unknown message type: #{type}"
  end
  @type = type

  @id = id

  if message && !message.is_a?(String)
    raise "String object expected as message but got #{message.class}"
  end
  @message = message

  if sourceFileInfo && !sourceFileInfo.is_a?(TextParser::SourceFileInfo)
    raise "SourceFileInfo object expected but got #{sourceFileInfo.class}"
  end
  @sourceFileInfo = sourceFileInfo

  if line && !line.is_a?(String)
    raise "String object expected as line but got #{line.class}"
  end
  @line = line

  @data = data

  if scenario && !scenario.is_a?(Scenario)
    raise "Scenario object expected by got #{scenario.class}"
  end
  @scenario = scenario
end

Public Instance Methods

to_log() click to toggle source

Convert the Message into a String that can be stored in a log file.

# File lib/taskjuggler/MessageHandler.rb, line 96
def to_log
  str = ""
  # The SourceFileInfo is printed as <fileName>:line:
  if @sourceFileInfo
    str += "#{@sourceFileInfo.fileName}:#{sourceFileInfo.lineNo}: "
  end
  str += "Scenario #{@scenario.id}: " if @scenario
  str += @message
  str
end
to_s() click to toggle source

Convert the Message into a String that can be printed to the console.

# File lib/taskjuggler/MessageHandler.rb, line 77
def to_s
  str = ""
  # The SourceFileInfo is printed as <fileName>:line:
  if @sourceFileInfo
    str += "#{@sourceFileInfo.fileName}:#{sourceFileInfo.lineNo}: "
  end
  if @scenario
    tag = "#{@type.to_s.capitalize} in scenario #{@scenario.id}: "
  else
    tag = "#{@type.to_s.capitalize}: "
  end
  colors = { :fatal => red, :error => red, :warning => magenta,
             :info => blue, :debug => green }
  str += colors[@type] + tag + @message + reset
  str += "\n" + @line if @line
  str
end