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



10
11
12
13
14
# File 'lib/lhc/interceptors.rb', line 10

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.



7
8
9
# File 'lib/lhc/interceptors.rb', line 7

def all
  @all
end

Instance Method Details

#intercept(name) ⇒ Object

Forwards messages to interceptors and handles provided responses.



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

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