Sha256: 1f63727fcea8d31360a15bbbb5239226bc5b684d069c6fb4ffbb045d31f4155a

Contents?: true

Size: 741 Bytes

Versions: 2

Compression:

Stored size: 741 Bytes

Contents

require 'stringio'
require 'escape_utils'

module Nirvana
  module Util
    extend self

    def capture_stdout
      out = StringIO.new
      $stdout = out
      yield
      return out.string
    ensure
      $stdout = STDOUT
    end

    def capture_stderr
      out = StringIO.new
      $stderr = out
      yield
      return out.string
    ensure
      $stderr = STDERR
    end

    def capture_all
      stdout, stderr, result = nil
      stderr = capture_stderr do
        stdout = capture_stdout do
          result = yield
        end
      end
      [stdout, stderr, result]
    end

    def format_output(response)
      EscapeUtils.escape_html(response).gsub("\n", "<br>").gsub("\t", "    ").gsub(" ", "&nbsp;")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nirvana-0.1.1 lib/nirvana/util.rb
nirvana-0.1.0 lib/nirvana/util.rb