From 4c2d1b89b3a8c6dd4117fac23589c41b953dbb02 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:30:04 +0100 Subject: [PATCH] better titles --- lib/travis/api/app/stack_instrumentation.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index 51b28fb2..7e8e9a63 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -5,7 +5,7 @@ class Travis::Api::App class Middleware def initialize(app, title = nil) @app = app - @title = title || "Rack: use #{app.class.name}" + @title = title || StackInstrumentation.title_for(app, :use) end def call(env) @@ -22,18 +22,28 @@ class Travis::Api::App end end + def self.title_for(verb, object) + object &&= case object + when ::Sinatra::Wrapper then object.settings.inspect + when Class, Module then object.inspect + when String then object + else object.class.inspect + end + "Rack: #{verb} #{object}" + end + def use(*) super(Middleware) super end def run(app) - super Middleware.new(app, "Rack: run %p" % app.class) + super Middleware.new(app, StackInstrumentation.title_for(app, :run)) end def map(path, &block) super(path) do - use(Middleware, "Rack: map %p" % path) + use(Middleware, StackInstrumentation.title_for(path, :map)) extend StackInstrumentation instance_eval(&block) end