require "rack/utils" require "rack/var_dump/object" require "rack/var_dump/version" module Rack class VarDump include Object @@var_aggregates = [] def self.var_dump(var) @@var_aggregates << var.to_yaml rescue => e if defined?(Rails) ::Rails.logger.warn "Rack::VarDump[warn] #{e}" end if var.respond_to?(:inspect) @@var_aggregates << var.inspect end end def self.reset! @@var_aggregates = [] end def initialize(app) @app = app end def call(env) request = Rack::Request.new(env) status, headers, response = @app.call(env) if /^text\/html/ =~ headers["Content-Type"] && !@@var_aggregates.empty? body = "" response.each {|org_body| body << org_body} response = [apply(request, body)] if body =~ /
) html << Rack::Utils.escape_html(@@var_aggregates.join) html << %Q(