Class: Eyeloupe::RequestMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/eyeloupe/request_middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestMiddleware

Returns a new instance of RequestMiddleware.



11
12
13
14
15
# File 'lib/eyeloupe/request_middleware.rb', line 11

def initialize(app)
  @app = app
  @inrequest_processor = Processors::InRequest.instance
  @exception_processor = Processors::Exception.instance
end

Instance Attribute Details

#exception_processorEyeloupe::Processors::Exception



9
10
11
# File 'lib/eyeloupe/request_middleware.rb', line 9

def exception_processor
  @exception_processor
end

#inrequest_processorEyeloupe::Processors::InRequest



6
7
8
# File 'lib/eyeloupe/request_middleware.rb', line 6

def inrequest_processor
  @inrequest_processor
end

Instance Method Details

#call(env) ⇒ Object

Parameters:

  • env (Hash)

    Rack environment



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/eyeloupe/request_middleware.rb', line 18

def call(env)

  request = ActionDispatch::Request.new(env)
  ex = nil

  if enabled?(request) && !skip_request?(request)
    @inrequest_processor.start_timer

    begin
      status, headers, response = @app.call(env)

      framework_exception = env['action_dispatch.exception']
      if framework_exception
        ex = @exception_processor.process(env, framework_exception)
      end

      [status, headers, response]
    rescue Exception => e
      exception = ActionDispatch::ExceptionWrapper.new(env, e)
      status = exception.status_code
      headers = {}
      response = e.message
      ex = @exception_processor.process(env, e)
      raise
    ensure
      @inrequest_processor.init(request, env, status, headers, response, ex).process
    end
  else
    @app.call(env)
  end

end