summary refs log tree commit
diff options
context:
space:
mode:
authorStephen Best <bestie@gmail.com>2013-08-10 20:15:38 +0100
committerJames Tucker <jftucker@gmail.com>2014-07-13 14:02:29 -0700
commit893a2c505a3a43b4f224b50ea06567dacb473cae (patch)
tree9ab91384f7885ea2035b41bba7f627557b6eafd8
parent2ab24cf3590fc1fa6cf551841ef97edf2cdf1ebf (diff)
downloadrack-893a2c505a3a43b4f224b50ea06567dacb473cae.tar.gz
ShowExceptions minor refactoring
* Load HTML exception template only if needed
* Only #call is public
* Enumerable body concern in one place
-rw-r--r--lib/rack/showexceptions.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/rack/showexceptions.rb b/lib/rack/showexceptions.rb
index 39499d5e..0e8a5952 100644
--- a/lib/rack/showexceptions.rb
+++ b/lib/rack/showexceptions.rb
@@ -17,7 +17,6 @@ module Rack
 
     def initialize(app)
       @app = app
-      @template = ERB.new(TEMPLATE)
     end
 
     def call(env)
@@ -33,15 +32,21 @@ module Rack
         body = pretty(env, e)
       else
         content_type = "text/plain"
-        body = [exception_string]
+        body = exception_string
       end
 
-      [500,
-       {"Content-Type" => content_type,
-        "Content-Length" => Rack::Utils.bytesize(body.join).to_s},
-       body]
+      [
+        500,
+        {
+          "Content-Type" => content_type,
+          "Content-Length" => Rack::Utils.bytesize(body).to_s,
+        },
+        [body],
+      ]
     end
 
+    private
+
     def accepts_html?(env)
       env["HTTP_ACCEPT"] && env["HTTP_ACCEPT"].include?("text/html")
     end
@@ -85,7 +90,7 @@ module Rack
         end
       }.compact
 
-      [@template.result(binding)]
+      ERB.new(TEMPLATE).result(binding)
     end
 
     def h(obj)                  # :nodoc: