class Jisota::Output

Responsible for outputting to the user / log file / whatever

Will default to use STDOUT and STDERR, but that can be overwritten in the initializer

Attributes

indent_level[RW]
prefix[RW]
stderr[RW]
stdout[RW]
verbose[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/jisota/output.rb, line 10
def initialize(options = {})
  @stdout  = options.fetch(:stdout) { $stdout }
  @stderr  = options.fetch(:stderr) { $stderr }
  @verbose = options.fetch(:verbose) { false }
  @prefix = options.fetch(:prefix) { "-----> " }
  @indent_level = 0
end

Public Instance Methods

error(message) click to toggle source
# File lib/jisota/output.rb, line 35
def error(message)
  stderr.write(message)
  stderr.flush
end
indent() { || ... } click to toggle source
# File lib/jisota/output.rb, line 40
def indent
  self.indent_level += 1
  if block_given?
    begin
      yield
    ensure
      outdent
    end
  end
end
info(message) click to toggle source
# File lib/jisota/output.rb, line 25
def info(message)
  stdout.write(message) if verbose
  stdout.flush
end
outdent() click to toggle source
# File lib/jisota/output.rb, line 51
def outdent
  self.indent_level -= 1
end
system_message(message, &block) click to toggle source
# File lib/jisota/output.rb, line 18
def system_message(message, &block)
  result = ["", prefix, "  " * indent_level, message, "\n"].join
  stdout.write(result)
  stdout.flush
  indent(&block) if block_given?
end
warn(message) click to toggle source
# File lib/jisota/output.rb, line 30
def warn(message)
  stderr.write(message) if verbose
  stderr.flush
end