class Needle::Interceptor::DynamicInterceptor

This is the wrapper for on-the-fly interceptors that have been created via Needle::Interceptor#doing. The callback registered with Needle::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 Needle::Interceptor#doing method to create dynamic interceptors.

Public Class Methods

new( callback ) click to toggle source

Create a new DynamicInterceptor instance that wraps the given callback.

# File lib/needle/interceptor.rb, line 48
def initialize( callback )
  @callback = callback
end

Public Instance Methods

new( point, opts ) click to toggle source

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.

# File lib/needle/interceptor.rb, line 56
def new( point, opts )
  @point = point
  @options = opts
  self
end
process( chain, context ) click to toggle source

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).

# File lib/needle/interceptor.rb, line 67
def process( chain, context )
  context.data[:options] = @options
  context.data[:point] = @point
  @callback.call( chain, context )
end