Class: Deas::ShowExceptions

Inherits:
Object
  • Object
show all
Defined in:
lib/deas/show_exceptions.rb

Defined Under Namespace

Classes: Body

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ShowExceptions

Returns a new instance of ShowExceptions.



7
8
9
# File 'lib/deas/show_exceptions.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

The Rack call interface. The receiver acts as a prototype and runs each request in a clone object unless the rack.run_once variable is set in the environment. Ripped from: github.com/rtomayko/rack-cache/blob/master/lib/rack/cache/context.rb



15
16
17
18
19
20
21
# File 'lib/deas/show_exceptions.rb', line 15

def call(env)
  if env['rack.run_once']
    call! env
  else
    clone.call! env
  end
end

#call!(env) ⇒ Object

The real Rack call interface.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/deas/show_exceptions.rb', line 24

def call!(env)
  status, headers, body = @app.call(env)
  if error = env['deas.error']
    error_body = Body.new(error)

    headers['Content-Length'] = error_body.size.to_s
    headers['Content-Type']   = error_body.mime_type.to_s
    body = [error_body.content]
  end
  [status, headers, body]
end