Class TaskJuggler::Message
In: lib/taskjuggler/MessageHandler.rb
Parent: Object

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

Methods

new   to_s  

Included Modules

Term::ANSIColor

Attributes

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

Public Class methods

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.

[Source]

# File lib/taskjuggler/MessageHandler.rb, line 39
    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

Convert the Message into a String.

[Source]

# File lib/taskjuggler/MessageHandler.rb, line 72
    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

[Validate]