Class: DHC::Interceptors
- Inherits:
-
Object
- Object
- DHC::Interceptors
- Defined in:
- lib/dhc/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/dhc/interceptors.rb', line 10 def initialize(request) self.all = (request.[:interceptors] || DHC.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/dhc/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/dhc/interceptors.rb', line 17 def intercept(name) all.each do |interceptor| result = interceptor.send(name) if result.is_a? DHC::Response raise 'Response already set from another interceptor' if @response @response = interceptor.request.response = result end end end |