Class: LHC::Interceptors
- Inherits:
-
Object
- Object
- LHC::Interceptors
- 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
-
#all ⇒ Object
Returns the value of attribute all.
Instance Method Summary collapse
-
#initialize(request) ⇒ Interceptors
constructor
Intitalizes and determines if global or local interceptors are used.
-
#intercept(name) ⇒ Object
Forwards messages to interceptors and handles provided responses.
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.[:interceptors] || LHC.config.interceptors).map do |interceptor| interceptor.new(request) end end |
Instance Attribute Details
#all ⇒ Object
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 |