Module: Nirvana::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/nirvana/util.rb

Instance Method Summary collapse

Instance Method Details

#capture_allObject



26
27
28
29
30
31
32
33
34
# File 'lib/nirvana/util.rb', line 26

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

#capture_stderrObject



17
18
19
20
21
22
23
24
# File 'lib/nirvana/util.rb', line 17

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

#capture_stdoutObject



8
9
10
11
12
13
14
15
# File 'lib/nirvana/util.rb', line 8

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

#format_output(response) ⇒ Object



36
37
38
# File 'lib/nirvana/util.rb', line 36

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