Class: LHC::Interceptors

Inherits:
Object
  • Object
show all
Defined in:
lib/lhc/interceptors.rb

Overview

Handles interceptions during the lifecycle of a request Represents all active interceptors for a request/response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Interceptors

Intitalizes and determines if global or local interceptors are used



8
9
10
11
12
# File 'lib/lhc/interceptors.rb', line 8

def initialize(request)
  self.all = (request.options[:interceptors] || LHC.config.interceptors).map do |interceptor|
    interceptor.new(request)
  end
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



5
6
7
# File 'lib/lhc/interceptors.rb', line 5

def all
  @all
end

Instance Method Details

#intercept(name) ⇒ Object

Forwards messages to interceptors and handles provided responses.



15
16
17
18
19
20
21
22
23
# File 'lib/lhc/interceptors.rb', line 15

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