Sha256: 650f337a58267cf12351c825c3f4b9f722728c123324f42c8c2d4e5681af9bcd

Contents?: true

Size: 902 Bytes

Versions: 6

Compression:

Stored size: 902 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
        raise '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

6 entries across 6 versions & 1 rubygems

Version Path
lhc-3.8.1 lib/lhc/interceptor_processor.rb
lhc-3.8.0 lib/lhc/interceptor_processor.rb
lhc-3.7.3 lib/lhc/interceptor_processor.rb
lhc-3.7.2 lib/lhc/interceptor_processor.rb
lhc-3.7.2.1 lib/lhc/interceptor_processor.rb
lhc-3.7.1 lib/lhc/interceptor_processor.rb