Sha256: 12eadb94e3a97485efed7170eecd400632d20afe8e9e97857b4b567d9a379379

Contents?: true

Size: 763 Bytes

Versions: 13

Compression:

Stored size: 763 Bytes

Contents

# 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

13 entries across 13 versions & 1 rubygems

Version Path
lhc-10.1.2 lib/lhc/interceptors.rb
lhc-10.1.1 lib/lhc/interceptors.rb
lhc-10.1.0 lib/lhc/interceptors.rb
lhc-10.0.2 lib/lhc/interceptors.rb
lhc-9.4.4 lib/lhc/interceptors.rb
lhc-10.0.1 lib/lhc/interceptors.rb
lhc-10.0.0 lib/lhc/interceptors.rb
lhc-9.4.3 lib/lhc/interceptors.rb
lhc-9.4.2 lib/lhc/interceptors.rb
lhc-9.4.1 lib/lhc/interceptors.rb
lhc-9.4.0 lib/lhc/interceptors.rb
lhc-9.3.1 lib/lhc/interceptors.rb
lhc-9.3.0 lib/lhc/interceptors.rb