Class: RackAfterReply::AppProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_after_reply/app_proxy.rb

Overview

Wraps a Rack app to intercept the rack environment passed to #call for access by the request handler after the socket is closed.

Instance Method Summary collapse

Constructor Details

#initialize(request_handler, app) ⇒ AppProxy

Returns a new instance of AppProxy.



7
8
9
10
# File 'lib/rack_after_reply/app_proxy.rb', line 7

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rack_after_reply/app_proxy.rb', line 19

def method_missing(name, *args, &block)
  class_eval <<-EOS
    def #{name}(*args, &block)
      @app.#{name}(*args, &block)
    end
  EOS
  send(name, *args, &block)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
# File 'lib/rack_after_reply/app_proxy.rb', line 12

def call(env)
  callbacks = []
  env[RackAfterReply::CALLBACKS_KEY] = callbacks
  @request_handler.rack_after_reply_callbacks = callbacks
  @app.call(env)
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rack_after_reply/app_proxy.rb', line 28

def respond_to?(name, include_private=false)
  super || @app.respond_to?(name, include_private)
end