Sha256: 65976930312eb03456e4823ecf4b8cfe248964b310862dd0ad81059e9c11f1a0

Contents?: true

Size: 794 Bytes

Versions: 37

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

# Handles interceptions during the lifecycle of a request
# Represents all active interceptors for a request/response.
class LHC::Interceptors

  attr_accessor :all

  # Intitalizes and determines if global or local interceptors are used
  def initialize(request)
    self.all = (request.options[:interceptors] || LHC.config.interceptors).map do |interceptor|
      interceptor.new(request)
    end
  end

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

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
lhc-13.2.0 lib/lhc/interceptors.rb
lhc-13.1.0 lib/lhc/interceptors.rb
lhc-13.0.0 lib/lhc/interceptors.rb
lhc-12.3.0 lib/lhc/interceptors.rb
lhc-12.2.1 lib/lhc/interceptors.rb
lhc-12.2.0 lib/lhc/interceptors.rb
lhc-12.1.3 lib/lhc/interceptors.rb
lhc-12.1.2 lib/lhc/interceptors.rb
lhc-12.1.1 lib/lhc/interceptors.rb
lhc-12.1.0 lib/lhc/interceptors.rb
lhc-12.0.3 lib/lhc/interceptors.rb
lhc-12.0.2 lib/lhc/interceptors.rb
lhc-12.0.1 lib/lhc/interceptors.rb
lhc-12.0.0 lib/lhc/interceptors.rb
lhc-11.2.0 lib/lhc/interceptors.rb
lhc-11.1.1 lib/lhc/interceptors.rb
lhc-11.1.0 lib/lhc/interceptors.rb
lhc-11.0.2 lib/lhc/interceptors.rb
lhc-11.0.1 lib/lhc/interceptors.rb
lhc-11.0.0 lib/lhc/interceptors.rb