class Rack::BodyProxy

Proxy for response bodies allowing calling a block when the response body is closed (after the response has been fully sent to the client).

Public Class Methods

new(body, &block) click to toggle source

Set the response body to wrap, and the block to call when the response has been fully sent.

# File lib/rack/body_proxy.rb, line 9
def initialize(body, &block)
  @body = body
  @block = block
  @closed = false
end

Public Instance Methods

close() click to toggle source

If not already closed, close the wrapped body and then call the block the proxy was initialized with.

# File lib/rack/body_proxy.rb, line 22
def close
  return if @closed
  @closed = true
  begin
    @body.close if @body.respond_to? :close
  ensure
    @block.call
  end
end
closed?() click to toggle source

Whether the proxy is closed. The proxy starts as not closed, and becomes closed on the first call to close.

# File lib/rack/body_proxy.rb, line 34
def closed?
  @closed
end
method_missing(method_name, *args, &block) click to toggle source

Delegate missing methods to the wrapped body.

# File lib/rack/body_proxy.rb, line 39
def method_missing(method_name, *args, &block)
  @body.__send__(method_name, *args, &block)
end
respond_to_missing?(method_name, include_all = false) click to toggle source

Return whether the wrapped body responds to the method.

Calls superclass method
# File lib/rack/body_proxy.rb, line 16
def respond_to_missing?(method_name, include_all = false)
  super or @body.respond_to?(method_name, include_all)
end