Class: Deadweight::Rack::CapturingMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/deadweight/rack/capturing_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, dw) ⇒ CapturingMiddleware

Returns a new instance of CapturingMiddleware



4
5
6
7
# File 'lib/deadweight/rack/capturing_middleware.rb', line 4

def initialize(app, dw)
  @app = app
  @dw  = dw
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
# File 'lib/deadweight/rack/capturing_middleware.rb', line 9

def call(env)
  response = @app.call(env)
  process(response)
  response
end

#process(rack_response) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/deadweight/rack/capturing_middleware.rb', line 15

def process(rack_response)
  status, headers, response = rack_response

  if response.respond_to?(:body)
    html = response.body
    @dw.process!(html)
  end
end