### Home Classes Methods

### In Files

- lib/needle/definition-context.rb

### Parent

Object

### Methods

- ::new
- #has_key?
- #intercept
- #knows_key?
- #method_missing
- #namespace
- #namespace!
- #namespace_define
- #namespace_define!
- #require
- #this_container
- #use
- #use!

### Files

- README

### Class/Module Index

Quicksearch

- Needle
- Needle::Bug
- Needle::Container
- Needle::DefinitionContext
- Needle::IncludeExclude
- Needle::Interceptor
- Needle::Interceptor::DynamicInterceptor
- Needle::InterceptorChainBuilder
- Needle::InterceptorChainBuilder::InterceptedServiceProxy
- Needle::InterceptorChainBuilder::InterceptorChainElement
- Needle::InterceptorChainBuilder::ProxyObjectChainElement
- Needle::InterceptorConfigurationError
- Needle::Lifecycle
- Needle::Lifecycle::Deferred
- Needle::Lifecycle::Initialize
- Needle::Lifecycle::Multiton
- Needle::Lifecycle::Proxy
- Needle::Lifecycle::Singleton
- Needle::Lifecycle::Threaded
- Needle::LogFactory
- Needle::Logger
- Needle::LoggingInterceptor
- Needle::NeedleError
- Needle::Pipeline
- Needle::Pipeline::Collection
- Needle::Pipeline::Collection::BlockElement
- Needle::Pipeline::Element
- Needle::Pipeline::InterceptorElement
- Needle::QueryableMutex
- Needle::Registry
- Needle::ServiceNotFound
- Needle::ServicePoint
- Needle::Version

No matching classes.

# Needle::DefinitionContext

This class is used by the Container#define! and Container#namespace! methods to allow an `instance_eval`'d block to create new service points simply by invoking imaginary methods. It is basically an empty shell, with almost all of the builtin methods removed from it. (This allows services like "hash" and "print" to be defined, where they would normally conflict with the Kernel methods of the same name.)

### Public Class Methods

new( container ) click to toggle source

Create a new DefinitionContext that wraps the given container. All operations performed on this context will be delegated to the container.

    # File lib/needle/definition-context.rb, line 41
    def initialize( container )
      @container = container
    end

### Public Instance Methods

has_key?( name ) click to toggle source

Delegates to Container#has_key?.

    # File lib/needle/definition-context.rb, line 103
    def has_key?( name )
      @container.has_key?( name )
    end

intercept( name ) click to toggle source

Delegate to Container#intercept.

    # File lib/needle/definition-context.rb, line 52
    def intercept( name )
      @container.intercept( name )
    end

knows_key?( name ) click to toggle source

Delegates to Container#knows_key?.

    # File lib/needle/definition-context.rb, line 108
    def knows_key?( name )
      @container.knows_key?( name )
    end

method_missing( sym, *args, &block ) click to toggle source

Any method invocation with no block and no parameters is interpreted to be a service reference on the wrapped container, and delegates to Container#[]. If the block is not given but the args are not empty, a NoMethodError will be raised.

If a block is given, this delegates to Container#register, leaving all parameters in place.

    # File lib/needle/definition-context.rb, line 119
    def method_missing( sym, *args, &block )
      if block.nil?
        @container.get( sym, *args )
      else
        @container.register( sym, *args, &block )
      end
    end

namespace( *parms, &block ) click to toggle source

Delegate to Container#namespace.

    # File lib/needle/definition-context.rb, line 57
    def namespace( *parms, &block )
      @container.namespace( *parms, &block )
    end

namespace!( *parms, &block ) click to toggle source
Alias for: namespace_define!
namespace_define( *parms, &block ) click to toggle source

Delegate to Container#define on the new namespace.

    # File lib/needle/definition-context.rb, line 69
    def namespace_define( *parms, &block )
      @container.namespace( *parms ) { |ns| ns.define( &block ) }
    end

namespace_define!( *parms, &block ) click to toggle source

Delegate to Container#namespace_define!.

    # File lib/needle/definition-context.rb, line 62
    def namespace_define!( *parms, &block )
      @container.namespace_define!( *parms, &block )
    end

Also aliased as: namespace!
require( *parms ) click to toggle source

Delegate to Container#require on the current container.

    # File lib/needle/definition-context.rb, line 74
    def require( *parms )
      # this is necessary to work around an rdoc bug...rdoc doesn't like
      # calling require with a variable number of arguments.
      @container.__send__( :require, *parms )
    end

this_container() click to toggle source

A way to access the container reference being operated on from within the context.

    # File lib/needle/definition-context.rb, line 47
    def this_container
      @container
    end

use( opts, &block ) click to toggle source

Delegate to Container#use on the current container, but yields the definition context instead of the container.

    # File lib/needle/definition-context.rb, line 82
    def use( opts, &block )
      use! @container.defaults.merge( opts ), &block
    end

use!( opts ) click to toggle source

Delegate to Container#use! on the current container, but yields the definition context instead of the container.

    # File lib/needle/definition-context.rb, line 88
    def use!( opts )
      original = @container.use!( opts )

      if block_given?
        begin
          yield self
        ensure
          @container.use! original
        end
      end

      original
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.