class TraceHeader

Constants

VERSION

Public Class Methods

new(app) click to toggle source
# File lib/trace_header.rb, line 9
def initialize(app)
  @app       = app
  @outputs   = []
  @fixed_app = nil
end

Public Instance Methods

call(env) click to toggle source
# File lib/trace_header.rb, line 15
def call(env)
  tracer.enable { @app.call(env) }
  display(result)
  @fixed_app
end

Private Instance Methods

called_rack_middleware?() click to toggle source
# File lib/trace_header.rb, line 24
def called_rack_middleware?
  method_id.eql?(:call) && binding.local_variable_defined?(:env)
end
result() click to toggle source
# File lib/trace_header.rb, line 47
def result
  TraceHeader::Result.new(@app, @outputs)
end
tracer() click to toggle source
# File lib/trace_header.rb, line 30
def tracer
  TracePoint.new(:call, :return) do |tp|
    if tp.called_rack_middleware?
      if tp.event.eql?(:call) \
        && !@outputs.find { |input| input[:middleware].eql? tp.defined_class }
        @outputs << { middleware: tp.defined_class,
                      app: tp.self.deep_dup,
                      env: tp.binding.local_variable_get(:env).deep_dup }
      end

      if tp.event.eql?(:return)
        @fixed_app = tp.return_value
      end
    end
  end
end