aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/middleware.rb
blob: fac0ed264514a047dff8e633eb0635b2356a9a65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module ActionController
  class Middleware < Metal
    class ActionMiddleware
      def initialize(controller)
        @controller = controller
      end

      def call(env)
        controller = @controller.allocate
        controller.send(:initialize)
        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
      @_request = ActionDispatch::Request.new(env)
      @_response = ActionDispatch::Response.new
      @_response.request = @_request
      process(:index)
    end
    
    def index
      call(env)
    end
  end
end