Sha256: d80f91316f5c60efb5f21e42590febf8b12a06c6a9752e28d177ce1e564da520

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

class Lecter::Rack
  def initialize(app)
    @app = app
  end

  def call(env)
    request = Rack::Request.new(env)
    if request.params['lecter_analysis']
      thread = Thread.current
      thread[:items] = ''
      tp = TracePoint.new(:line, :class, :call, :c_call, :return) do |tp|
        if tp.path &&
          !tp.path.include?('/app/views') &&
          !tp.path.include?('/app/helpers') &&
          tp.path.include?(Rails.root.to_s) &&
          tp.method_id != :method_added &&
          tp.defined_class != Module &&
          tp.defined_class != Class &&
          tp.defined_class != String &&
          tp.defined_class != Kernel &&
          tp.defined_class != NilClass

          thread[:items] += [tp.path, tp.lineno, tp.defined_class, tp.method_id, tp.event].join(' ') + ';'
        end
      end
      tp.enable
    end
    status, headers, response = @app.call(env)
    if tp
      status = 200
      response = [thread[:items]]
    end

    [status, headers, response]
  ensure
    tp.disable if tp
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lecter-0.1.5 lib/lecter/rack.rb
lecter-0.1.4 lib/lecter/rack.rb
lecter-0.1.3 lib/lecter/rack.rb