Sha256: da572a2f1e6f140168586f6ec1df4320fe824aa11dccc55574cc320673967d4e

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

# Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
# Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
# License::   LGPL
# $Id: /w/fey/uttk/trunk/lib/uttk/dumpers/Dumper.rb 22102 2006-02-21T23:03:39.538964Z pouillar  $


module Uttk

  # Dumpers are backends of Uttk.
  # You can easily write your own dumper. See Uttk::Dumpers::Dumper
  module Dumpers

    # The dumper is a specific Logger::Backend.
    #
    # It react to method calls by writting in the output.
    # The output must be acceded like that:
    #
    #   * Using the print method
    #   * Using the puts method
    #   * Using the << method
    #
    # If you really need to access to the real outputs use each_output.
    #
    # You can safely call flush in your methods because this method take care
    # of closed and unflushable outputs.
    class Dumper < Logger::Backend
      include Abstract
      attr_accessor :options

      def initialize ( output=STDOUT, *args )
        @outputs = [output]
        while args.first.is_a? IO do
          @outputs << args.shift
        end
        @options = args
        super()
      end


      def flush
        each_output do |o|
          o.flush if o.respond_to? :flush and (not o.closed?)
        end
      end


      def each_output ( &block )
        @outputs.each(&block)
      end


      def puts ( *args )
        each_output do |o|
          o.puts(*args)
        end
      end


      def print ( *args )
        each_output do |o|
          o.print(*args)
        end
      end


      def << ( arg )
        each_output do |o|
          o << arg
        end
        self
      end

    end # class Dumper

  end # module Dumpers

end # module Uttk

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
uttk-0.3.1.2 lib/uttk/dumpers/Dumper.rb
uttk-0.3.6.1 lib/uttk/dumpers/Dumper.rb
uttk-0.3.5.0 lib/uttk/dumpers/Dumper.rb
uttk-0.4.5.0 lib/uttk/dumpers/Dumper.rb
uttk-0.4.6.1 lib/uttk/dumpers/Dumper.rb
uttk-0.4.6.2 lib/uttk/dumpers/Dumper.rb