class ActiveTracker::OutputCapturer
Public Class Methods
new(app)
click to toggle source
# File lib/active_tracker/output_capturer.rb, line 3 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/active_tracker/output_capturer.rb, line 7 def call(env) start_time = Time.current status, headers, response = @app.call(env) [status, headers, response] ensure capture(response, headers) duration = (Time.current.to_f - start_time.to_f) * 1000 ActiveTracker::Plugin::Request.record_duration(duration) end
capture(response, headers)
click to toggle source
# File lib/active_tracker/output_capturer.rb, line 17 def capture(response, headers) body = response.body rescue nil unless body.is_a?(String) body = body.to_a rescue [body.body] rescue "No body given" end if body.respond_to?(:each) output = [] body.each do |line| output << line end output = output.join("\n") else output = body.to_s end ActiveTracker::Plugin::Request.output_capture(output, headers["Content-type"]) end