travis-api/lib/travis/api/app/stack_instrumentation.rb
Konstantin Haase 4a6dabaa0e fix typo
2015-01-14 16:21:07 +01:00

43 lines
832 B
Ruby

require 'travis/api/app'
class Travis::Api::App
module StackInstrumentation
class Middleware
def initialize(app, title = nil)
@app = app
@title = title || "Rack: use #{app.class.name}"
end
def call(env)
instrument { @app.call(env) }
end
def instrument(&block)
return yield unless instrument?
::Skylight.instrument(title: @title, &block)
end
def instrument?
defined? ::Skylight
end
end
def use(*)
super(Middleware)
super
end
def run(app)
super Middleware.new(app, "Rack: run %p" % app.class)
end
def map(path, &block)
super(path) do
use(Middleware, "Rack: map %p" % path)
extend StackInstrumentation
instance_eval(&block)
end
end
end
end