Sha256: a9ead3705eb15f24b1e87e25917d0f1bde3983e7c66e8a743ccc68fed11f3d31

Contents?: true

Size: 1.53 KB

Versions: 46

Compression:

Stored size: 1.53 KB

Contents

#--
# Copyright (c) 2008 Jeremy Hinegardner
# All rights reserved.  See LICENSE and/or COPYING for details.
#++

require 'amalgalite/profile_tap'
require 'stringio'

module Amalgalite
  module Taps
    #
    # An IOTap is an easy way to send all top information to andy IO based
    # object.  Both profile and trace tap information can be captured
    # This means you can send the events to STDOUT with:
    #
    #   db.profile_tap = db.trace_tap  = Amalgalite::Taps::Stdout.new
    #
    #
    class IO

      attr_reader :profile_tap
      attr_reader :io

      def initialize( io )
        @io = io
        @profile_tap = ProfileTap.new( self, 'output_profile_event' )
      end

      def trace( msg )
        io.puts msg 
      end

      # need a profile method, it routes through the profile tap which calls back
      # to output_profile_event
      def profile( msg, time )
        @profile_tap.profile(msg, time)
      end

      def output_profile_event( msg, time )
        io.puts "#{time} : #{msg}"
      end

      def dump_profile
        samplers.each_pair do |k,v|
          io.puts v.to_s
        end
      end

      def samplers
        profile_tap.samplers
      end
    end

    #
    # This class provides an IO tap that writes to a StringIO.  The result is
    # available via .to_s or .string.
    #
    class StringIO < ::Amalgalite::Taps::IO
      def initialize
        @stringio = ::StringIO.new
        super( @stringio )
      end

      def to_s
        @stringio.string
      end
      alias :string :to_s
    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
amalgalite-1.6.3-x86-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.6.3-x64-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.6.3 lib/amalgalite/taps/io.rb
amalgalite-1.6.1-x86-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.6.1-x64-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.6.1 lib/amalgalite/taps/io.rb
amalgalite-1.6.0-x64-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.6.0-x86-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.6.0 lib/amalgalite/taps/io.rb
amalgalite-1.5.0-x86-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.5.0 lib/amalgalite/taps/io.rb
amalgalite-1.4.1-x86-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.4.1 lib/amalgalite/taps/io.rb
amalgalite-1.4.0-x86-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.4.0 lib/amalgalite/taps/io.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/amalgalite-1.3.0/lib/amalgalite/taps/io.rb
amalgalite-1.3.0-x86-mswin32 lib/amalgalite/taps/io.rb
amalgalite-1.3.0 lib/amalgalite/taps/io.rb
amalgalite-1.1.2-x86-mingw32 lib/amalgalite/taps/io.rb
amalgalite-1.1.2-x86-mswin32 lib/amalgalite/taps/io.rb