Class | Needle::Interceptor |
In: |
lib/needle/interceptor.rb
|
Parent: | Object |
This represents the definition of an interceptor as it is attached to a service point. Instances of Interceptor are also used for configuring themselves programmatically.
You will almost never instantiate an Interceptor object directly. Instead, use the Container#intercept method. You can then configure the new interceptor by chaining methods of the new object together, quite readably:
container.intercept( :foo ).with! { some_interceptor }. with_options( :arg => :value )
You can also create new interceptors on the fly via the Interceptor#doing method.
options | [R] | The set of options that were given to this interceptor via the with_options method. |
Create a new Interceptor definition. By default, it has no implementation and a priority of 0.
Returns the action that was specified for this interceptor as a proc instance. This will either be the block passed to with, or a proc that wraps the instantiation of a DynamicInterceptor (when doing was used).
If neither with nor doing were specified, an InterceptorConfigurationError is raised.
This allows new interceptors to be defined "on-the-fly". The associated block must accept two parameters—an object representing the chain of interceptors, and the context of the current method invocation. The block should then invoke process_next on the chain (passing the context as the lone parameter) when the next element of the chain should be invoked.
You should only call doing once per interceptor, and never after invoking with on the same interceptor.
This is identical to with, but it wraps the block in another proc that calls instance_eval on the container, with the block.
Usage:
container.intercept( :foo ). with! { logging_interceptor }