Sha256: 94fd37cc1a9b581d8fd32e52fffad66bfaba8cc4b8aea83ddf82c97e08ee7953

Contents?: true

Size: 1.1 KB

Versions: 27

Compression:

Stored size: 1.1 KB

Contents

require 'base64'

module ZTK

  # UI Error Class
  #
  # @author Zachary Patten <zachary AT jovelabs DOT com>
  class UIError < Error; end

  # UI Class
  #
  # This class encapsulates a STDOUT, STDERR, STDIN
  # and logging device.
  #
  # @author Zachary Patten <zachary AT jovelabs DOT com>
  class UI < ZTK::Base

    attr_accessor :stdout, :stderr, :stdin, :logger

    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
    end

  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ztk-1.6.2 lib/ztk/ui.rb
ztk-1.6.1 lib/ztk/ui.rb
ztk-1.6.0 lib/ztk/ui.rb
ztk-1.5.5 lib/ztk/ui.rb
ztk-1.5.4 lib/ztk/ui.rb
ztk-1.5.3 lib/ztk/ui.rb
ztk-1.5.2 lib/ztk/ui.rb
ztk-1.5.1 lib/ztk/ui.rb
ztk-1.5.0 lib/ztk/ui.rb
ztk-1.4.22 lib/ztk/ui.rb
ztk-1.4.21 lib/ztk/ui.rb
ztk-1.4.20 lib/ztk/ui.rb
ztk-1.4.19 lib/ztk/ui.rb
ztk-1.4.18 lib/ztk/ui.rb
ztk-1.4.17 lib/ztk/ui.rb
ztk-1.4.16 lib/ztk/ui.rb
ztk-1.4.15 lib/ztk/ui.rb
ztk-1.4.14 lib/ztk/ui.rb
ztk-1.4.13 lib/ztk/ui.rb
ztk-1.4.12 lib/ztk/ui.rb