class Buryspam::Status

Class to display/update/remove status update messages during processing with the option of sending these messages to the Logger for logging. This class also has class methods to print and puts strings which cannot be updated/removed but which will be logged, by default.

Unlike the Logger methods, the Status methods generate output on $stdout or $stderr.

Public Class Methods

new(str = "", opts = {}) click to toggle source

Display the string str and log it, by default. The string can later be replaced on the display with the update method. The string should not have any special characters in it (tabs, newlines etc.). To disable logging, supply :log => false parameter for opts.

# File buryspam.rb, line 4159
def initialize(str = "", opts = {})
  params = { :log => true }.merge(opts)
  # Don't try something like:
  #   @str, @log = str, opts[:log] || true
  # because if you do,then @log will never be set false.
  @str, @log = str, params[:log]
  # We need to go up one extra step in the stack frame,
  # because 'initialize' is called by 'new'.
  Status.print(@str, :log => @log, :invoker => invoker(2))
end
print(msg, opts = {}) click to toggle source

Display the message string str on the appropriate stream and log it, if requested. The opts hash values are as follows:

  • :log: If false then don't log message. Default: true.

  • :flush: If true and msg doesn't end with newline, then flush the stream. Default: true.

  • :severity: The severity level at which to log msg. if :severity is :info or :debug then display msg on $stdout otherwise, send msg to $stderr. Default: :info.

  • :invoker: The calling method name to use when logging the message. Default: the name of the method that called print.

puts(msg = "", opts = {}) click to toggle source

Wrapper for the print method, but append a newline to msg if one already isn't there. For the opts options, see the print method.

# File buryspam.rb, line 4227
def puts(msg = "", opts = {})
  if msg[-1] != \n\
    msg += "\n"
  end
  Status.print(msg, { :invoker => invoker }.merge(opts))
end

Public Instance Methods

finish() click to toggle source

Remove the string (created/displayed by new) from the display.

# File buryspam.rb, line 4181
def finish
  update("")
end
update(str) click to toggle source

Replace the string displayed earlier with the given string str.

# File buryspam.rb, line 4171
def update(str)
  return if str == @str
  Status.print("" * @str.length, :flush => false, :log => false)
  diff = @str.length - str.length
  blank = diff > 0 ? " " * diff + "" * diff : ""
  Status.print(str + blank, :log => @log, :invoker => invoker)
  @str = str
end