Skip to content

Commit

Permalink
Update AC::Middleware to play better with the normal AC::Metal stack.…
Browse files Browse the repository at this point in the history
… This required stopping to use #call for non-rack-related stuff
  • Loading branch information
Yehuda Katz authored and Yehuda Katz committed Nov 5, 2009
1 parent b0dfd1d commit b12f194
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions actionpack/lib/action_controller/metal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def controller_path
# and response object available. You might wish to control the
# environment and response manually for performance reasons.

attr_internal :status, :headers, :content_type, :app, :response
attr_internal :status, :headers, :content_type, :response

def initialize(*)
@_headers = {}
Expand All @@ -69,7 +69,7 @@ def location=(url)
end

# :api: private
def call(name, env)
def dispatch(name, env)
@_env = env
process(name)
to_a
Expand All @@ -95,7 +95,7 @@ def initialize(controller, action)
end

def call(env)
controller = @controller.new.call(@action, env)
@controller.new.dispatch(@action, env)
end
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/rack_convenience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module RackConvenience
attr_internal :request
end

def call(name, env)
def dispatch(action, env)
@_request = ActionDispatch::Request.new(env)
@_response = ActionDispatch::Response.new
@_response.request = request
Expand Down
40 changes: 20 additions & 20 deletions actionpack/lib/action_controller/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
module ActionController
class Middleware < Metal
class ActionMiddleware
def initialize(controller)
@controller = controller
def initialize(controller, app)
@controller, @app = controller, app
end

def call(env)
controller = @controller.allocate
controller.send(:initialize)
controller.app = @app
controller._call(env)
@controller.build(@app).dispatch(:index, env)
end
end

class << self
alias build new

def app=(app)
@app = app
def new(app)
ActionMiddleware.new(self, app)
end
end

def self.new(app)
middleware = ActionMiddleware.new(self)
middleware.app = app
middleware

attr_internal :app

def process(action)
response = super
self.status, self.headers, self.response_body = response if response.is_a?(Array)
response
end

def _call(env)
@_env = env
@_request = ActionDispatch::Request.new(env)
@_response = ActionDispatch::Response.new
@_response.request = @_request
process(:index)

def initialize(app)
super()
@_app = app
end

def index
Expand Down

0 comments on commit b12f194

Please sign in to comment.