Class: Needle::Interceptor::DynamicInterceptor
- Inherits:
-
Object
- Object
- Needle::Interceptor::DynamicInterceptor
- Defined in:
- lib/needle/interceptor.rb
Overview
This is the wrapper for on-the-fly interceptors that have been created via Interceptor#doing. The callback registered with Interceptor#doing gets wrapped by an instance of this class, to comply with the interface required by InterceptorChainBuilder.
This class should rarely (if ever) be instantiated directly. Instead, using the Interceptor#doing method to create dynamic interceptors.
Instance Method Summary collapse
-
#initialize(callback) ⇒ DynamicInterceptor
constructor
Create a new DynamicInterceptor instance that wraps the given callback.
-
#new(point, opts) ⇒ Object
This method is a concession to the required interceptor factory interface.
-
#process(chain, context) ⇒ Object
Process this link in the interceptor chain.
Constructor Details
#initialize(callback) ⇒ DynamicInterceptor
Create a new DynamicInterceptor instance that wraps the given callback.
48 49 50 |
# File 'lib/needle/interceptor.rb', line 48 def initialize( callback ) @callback = callback end |
Instance Method Details
#new(point, opts) ⇒ Object
This method is a concession to the required interceptor factory interface. It should return the new interceptor, configured to be attached to the given service point, and with the given options. It will always return self
.
56 57 58 59 60 |
# File 'lib/needle/interceptor.rb', line 56 def new( point, opts ) @point = point @options = opts self end |
#process(chain, context) ⇒ Object
Process this link in the interceptor chain. This will invoke the wrapped callback, passing in the chain and context parameters. Before invoking the callback, the options and service point references that were given in #new are assigned to context data members (so they can be referenced inside the callback).
67 68 69 70 71 |
# File 'lib/needle/interceptor.rb', line 67 def process( chain, context ) context.data[:options] = @options context.data[:point] = @point @callback.call( chain, context ) end |