class ZTK::UI

UI Class

This class encapsulates a STDOUT, STDERR, STDIN and logging device.

@author Zachary Patten <zpatten AT jovelabs DOT io>

Attributes

logger[RW]
quiet[RW]
stderr[RW]
stdin[RW]
stdout[RW]
verbose[RW]

Public Class Methods

new(configuration={}) click to toggle source
# File lib/ztk/ui.rb, line 23
def initialize(configuration={})
  defined?(Rails) and (rails_logger = Rails.logger)
  null_logger = (::ZTK::Logger.new("/dev/null") rescue ::Logger.new("/dev/null"))

  @stdout = (configuration[:stdout] || $stdout || STDOUT)
  @stderr = (configuration[:stderr] || $stderr || STDERR)
  @stdin  = (configuration[:stdin]  || $stdin  || STDIN)
  @logger = (configuration[:logger] || $logger || rails_logger || null_logger)

  (@stdout && @stdout.respond_to?(:sync=)) and @stdout.sync = true
  (@stderr && @stderr.respond_to?(:sync=)) and @stderr.sync = true
  (@stdin  && @stdin.respond_to?(:sync=))  and @stdin.sync  = true
  (@logger && @logger.respond_to?(:sync=)) and @logger.sync = true

  @verbose = (configuration[:verbose] || false)
  @quiet   = (configuration[:quiet]   || false)
end

Public Instance Methods

quiet?() click to toggle source
# File lib/ztk/ui.rb, line 45
def quiet?
  (@quiet == true)
end
verbose?() click to toggle source
# File lib/ztk/ui.rb, line 41
def verbose?
  (@verbose == true)
end