2009-08-26 03:18:52 -04:00
|
|
|
module ActionController
|
|
|
|
class Middleware < Metal
|
|
|
|
class ActionMiddleware
|
2009-11-05 18:38:04 -05:00
|
|
|
def initialize(controller, app)
|
|
|
|
@controller, @app = controller, app
|
2009-08-26 03:18:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2010-03-08 19:49:47 -05:00
|
|
|
request = ActionDispatch::Request.new(env)
|
|
|
|
@controller.build(@app).dispatch(:index, request)
|
2009-08-26 03:18:52 -04:00
|
|
|
end
|
2009-11-05 18:38:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class << self
|
|
|
|
alias build new
|
2009-08-26 03:18:52 -04:00
|
|
|
|
2009-11-05 18:38:04 -05:00
|
|
|
def new(app)
|
|
|
|
ActionMiddleware.new(self, app)
|
2009-08-26 03:18:52 -04:00
|
|
|
end
|
|
|
|
end
|
2009-11-05 18:38:04 -05:00
|
|
|
|
|
|
|
attr_internal :app
|
|
|
|
|
|
|
|
def process(action)
|
|
|
|
response = super
|
|
|
|
self.status, self.headers, self.response_body = response if response.is_a?(Array)
|
|
|
|
response
|
2009-08-26 03:18:52 -04:00
|
|
|
end
|
2009-11-05 18:38:04 -05:00
|
|
|
|
|
|
|
def initialize(app)
|
|
|
|
super()
|
|
|
|
@_app = app
|
2009-08-26 03:18:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|