Sha256: edf0352a29e05cfc7de55edf1c81d1f7dbe3c5733db6d50e369afac755ea97a0

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module StackTracy
  class Sinatra

    def initialize(app, arg = nil, options = {}, &before_filter)
      @app = app
      @arg = arg
      @options = options
      @before_filter = before_filter if block_given?
    end

    def call(env)
      request = ::Sinatra::Request.new env
      if request.path.match /^\/tracy(-.*)?/
        return open($1.to_s.gsub(/^-/, ""))
      end
      if @before_filter.nil? || !!@before_filter.call(request.path, request.params)
        result = nil
        stack_tracy @arg || Dir::tmpdir, @options do
          result = @app.call(env)
        end
        result
      else
        @app.call(env)
      end
    end

  private

    def open(match)
      if match.empty?
        if StackTracy.stack_trace.empty?
          StackTracy.open nil, false, @options[:threshold], @options[:limit]
        else
          StackTracy.dump do |file|
            StackTracy.open file, true, @options[:threshold], @options[:limit]
          end
        end
      else
        StackTracy.open match, false, @options[:threshold], @options[:limit]
      end
      [200, {"Content-Type" => "text/html;charset=utf-8", "Content-Length" => Rack::Utils.bytesize("").to_s}, ""]
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stack_tracy-0.1.4 lib/stack_tracy/sinatra.rb