diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-08-26 00:18:52 -0700 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-08-26 00:18:52 -0700 |
commit | 9408fcd2e858ae48dd30d9e8d1bb1dcbbfffb840 (patch) | |
tree | c16d280b988d662041fc5834d07078d9da6f2b37 /actionpack/lib/action_controller | |
parent | 78129b1731a1e6f3b091e996bcf55917d84b5f0e (diff) | |
download | rails-9408fcd2e858ae48dd30d9e8d1bb1dcbbfffb840.tar.gz rails-9408fcd2e858ae48dd30d9e8d1bb1dcbbfffb840.tar.bz2 rails-9408fcd2e858ae48dd30d9e8d1bb1dcbbfffb840.zip |
Create new ActionController::Middleware class that will work as a normal Rack middleware.
* This initial implementation is a bit hackish, but it uses a normal middleware API
so it's future-proof when we improve the internals.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/metal.rb | 22 | ||||
-rw-r--r-- | actionpack/lib/action_controller/middleware.rb | 34 |
2 files changed, 34 insertions, 22 deletions
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index aad9570237..51fbba3661 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -88,23 +88,6 @@ module ActionController end end - class ActionMiddleware - def initialize(controller, action) - @controller, @action = controller, action - end - - def call(env) - controller = @controller.new - controller.app = @app - controller.call(@action, env) - end - - def new(app) - @app = app - self - end - end - # Return a rack endpoint for the given action. Memoize the endpoint, so # multiple calls into MyController.action will return the same object # for the same action. @@ -118,10 +101,5 @@ module ActionController @actions ||= {} @actions[name.to_s] ||= ActionEndpoint.new(self, name) end - - def self.middleware(name) - @middlewares ||= {} - @middlewares[name.to_s] ||= ActionMiddleware.new(self, name) - end end end diff --git a/actionpack/lib/action_controller/middleware.rb b/actionpack/lib/action_controller/middleware.rb new file mode 100644 index 0000000000..5fccca0b48 --- /dev/null +++ b/actionpack/lib/action_controller/middleware.rb @@ -0,0 +1,34 @@ +module ActionController + class Middleware < Metal + class ActionMiddleware + def initialize(controller) + @controller = controller + end + + def call(env) + controller = @controller.allocate + controller.app = @app + controller._call(env) + end + + def app=(app) + @app = app + end + end + + def self.new(app) + middleware = ActionMiddleware.new(self) + middleware.app = app + middleware + end + + def _call(env) + @_env = env + process(:index) + end + + def index + call(env) + end + end +end
\ No newline at end of file |