Sha256: 1bc5bcd9f049699b38eb45d1af47f2f044e27bb830c8708f0c515be96c1c4f0c

Contents?: true

Size: 901 Bytes

Versions: 47

Compression:

Stored size: 901 Bytes

Contents

# Handles interceptions during the lifecycle of a request
class LHC::InterceptorProcessor

  attr_accessor :interceptors

  # Intitalizes the processor and determines if global or local interceptors are used
  def initialize(target)
    options = target.options if target.is_a? LHC::Request
    options ||= target.request.options if target.is_a? LHC::Response
    self.interceptors = (options[:interceptors] || LHC.config.interceptors).map { |i| i.new }
  end

  # Forwards messages to interceptors and handles provided responses.
  def intercept(name, target)
    interceptors.each do |interceptor|
      result = interceptor.send(name, target)
      if result.is_a? LHC::Response
        fail 'Response already set from another interceptor' if @response
        request = target.is_a?(LHC::Request) ? target : target.request
        @response = request.response = result
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
lhc-7.3.3 lib/lhc/interceptor_processor.rb
lhc-7.3.2 lib/lhc/interceptor_processor.rb
lhc-7.3.1 lib/lhc/interceptor_processor.rb
lhc-7.3.0 lib/lhc/interceptor_processor.rb
lhc-7.2.0 lib/lhc/interceptor_processor.rb
lhc-7.1.0 lib/lhc/interceptor_processor.rb
lhc-7.0.1 lib/lhc/interceptor_processor.rb
lhc-7.0.0 lib/lhc/interceptor_processor.rb
lhc-7.0.0.beta1 lib/lhc/interceptor_processor.rb
lhc-6.7.2 lib/lhc/interceptor_processor.rb
lhc-6.7.1 lib/lhc/interceptor_processor.rb
lhc-6.7.0 lib/lhc/interceptor_processor.rb
lhc-6.6.0.zipkin.pre.03 lib/lhc/interceptor_processor.rb
lhc-6.6.0.zipkin.pre.02 lib/lhc/interceptor_processor.rb
lhc-6.6.0.zipkin.pre.01 lib/lhc/interceptor_processor.rb
lhc-6.6.0.zipkin.pre lib/lhc/interceptor_processor.rb
lhc-6.6.0 lib/lhc/interceptor_processor.rb
lhc-6.5.0 lib/lhc/interceptor_processor.rb
lhc-6.4.0 lib/lhc/interceptor_processor.rb
lhc-6.3.1 lib/lhc/interceptor_processor.rb