3
module ActionController
5
@@default_lock = Mutex.new
6
cattr_accessor :default_lock
9
def initialize(body, lock)
15
@body.close if @body.respond_to?(:close)
17
Dispatcher.cleanup_application
21
def method_missing(*args, &block)
22
@body.send(*args, &block)
25
def respond_to?(symbol, include_private = false)
26
symbol == :close || @body.respond_to?(symbol, include_private)
30
def self.run(lock = @@default_lock)
33
Dispatcher.reload_application
34
status, headers, body = yield
35
# We do not want to call 'cleanup_application' in an ensure block
36
# because the returned Rack response body may lazily generate its data. This
37
# is for example the case if one calls
39
# render :text => lambda { ... code here which refers to application models ... }
41
# in an ActionController.
43
# Instead, we will want to cleanup the application code after the request is
44
# completely finished. So we wrap the body in a BodyWrapper class so that
45
# when the Rack handler calls #close during the end of the request, we get to
46
# run our cleanup code.
47
[status, headers, BodyWrapper.new(body, lock)]