Sha256: d7fc7029837c1308fd0a04715cae510f043d8de0d82716fcac15ba82d76abdc1

Contents?: true

Size: 795 Bytes

Versions: 12

Compression:

Stored size: 795 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

12 entries across 12 versions & 1 rubygems

Version Path
lhc-15.2.1 lib/lhc/interceptors.rb
lhc-15.2.0 lib/lhc/interceptors.rb
lhc-15.1.3 lib/lhc/interceptors.rb
lhc-15.1.2 lib/lhc/interceptors.rb
lhc-15.1.1 lib/lhc/interceptors.rb
lhc-15.1.0 lib/lhc/interceptors.rb
lhc-16.0.0.pre.pro2162.2 lib/lhc/interceptors.rb
lhc-16.0.0.pre.pro2162 lib/lhc/interceptors.rb
lhc-15.0.1 lib/lhc/interceptors.rb
lhc-15.0.0 lib/lhc/interceptors.rb
lhc-14.0.0 lib/lhc/interceptors.rb
lhc-13.4.0.pre.pro1766.1 lib/lhc/interceptors.rb