Sha256: 478dfe86e1e828b5420887e20a8a869629cadae8398a45fcf26b97a4d2256858

Contents?: true

Size: 930 Bytes

Versions: 4

Compression:

Stored size: 930 Bytes

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)
      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)
      StackTracy.open match.to_s.empty? ? nil : match, (match.to_s.empty? && @arg.to_s != "dump" && !StackTracy.stack_trace.empty?)
      [200, {"Content-Type" => "text/html;charset=utf-8", "Content-Length" => Rack::Utils.bytesize("").to_s}, ""]
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stack_tracy-0.1.3 lib/stack_tracy/sinatra.rb
stack_tracy-0.1.2 lib/stack_tracy/sinatra.rb
stack_tracy-0.1.1 lib/stack_tracy/sinatra.rb
stack_tracy-0.1.0 lib/stack_tracy/sinatra.rb