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
10 11 12 13 14 |
# File 'lib/lhc/interceptors.rb', line 10 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.
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 26 |
# 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 |