Class: LHC::InterceptorProcessor
- Inherits:
-
Object
- Object
- LHC::InterceptorProcessor
- Defined in:
- lib/lhc/interceptor_processor.rb
Overview
Handles interceptions during the lifecycle of a request
Instance Attribute Summary collapse
-
#interceptors ⇒ Object
Returns the value of attribute interceptors.
Instance Method Summary collapse
-
#initialize(target) ⇒ InterceptorProcessor
constructor
Intitalizes the processor and determines if global or local interceptors are used.
-
#intercept(name, target) ⇒ Object
Forwards messages to interceptors and handles provided responses.
Constructor Details
#initialize(target) ⇒ InterceptorProcessor
Intitalizes the processor and determines if global or local interceptors are used
7 8 9 10 11 |
# File 'lib/lhc/interceptor_processor.rb', line 7 def initialize(target) = target. if target.is_a? LHC::Request ||= target.request. if target.is_a? LHC::Response self.interceptors = ([:interceptors] || LHC.config.interceptors).map { |i| i.new } end |
Instance Attribute Details
#interceptors ⇒ Object
Returns the value of attribute interceptors.
4 5 6 |
# File 'lib/lhc/interceptor_processor.rb', line 4 def interceptors @interceptors end |
Instance Method Details
#intercept(name, target) ⇒ Object
Forwards messages to interceptors and handles provided responses.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lhc/interceptor_processor.rb', line 14 def intercept(name, target) interceptors.each do |interceptor| result = interceptor.send(name, target) if result.is_a? LHC::Response fail 'Response already set from another interceptor' if @response request = target.is_a?(LHC::Request) ? target : target.request @response = request.response = result end end end |