Class: Caliper::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/caliper/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) {|_self| ... } ⇒ Rack

Returns a new instance of Rack.

Yields:

  • (_self)

Yield Parameters:

  • _self (Caliper::Rack)

    the object that the method was called on



3
4
5
6
7
# File 'lib/caliper/rack.rb', line 3

def initialize(app, options = {}, &blk)
  @app = app

  yield self if block_given?
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/caliper/rack.rb', line 9

def call(env)
  if Caliper.config[:enabled] && !env['PATH_INFO'][/^\/assets/]
    env['caliper.tracer'] = Caliper::Tracer.new(env)
  end

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

  # check for routing error in rails way
  if @status == 404 && @headers['X-Cascade'] == 'pass'
    Caliper::AppError.create(
      ActionController::RoutingError.new("No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"),
      env
    )
  elsif env['caliper.tracer']
    env['caliper.tracer'].finish
  end

  [@status, @headers, @response]
rescue Exception => exception
  Caliper::AppError.create(exception, env)
  raise exception
end