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

Methods
Public Class methods
new( container )

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
41:     def initialize( container )
42:       @container = container
43:     end
Public Instance methods
has_key?( name )

Delegates to Container#has_key?.

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

Delegate to Container#intercept.

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

Delegates to Container#knows_key?.

     # File lib/needle/definition-context.rb, line 108
108:     def knows_key?( name )
109:       @container.knows_key?( name )
110:     end
method_missing( sym, *args, &block )

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
119:     def method_missing( sym, *args, &block )
120:       if block.nil?
121:         @container.get( sym, *args )
122:       else
123:         @container.register( sym, *args, &block )
124:       end
125:     end
namespace( *parms, &block )

Delegate to Container#namespace.

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

Alias for namespace_define!

namespace_define( *parms, &block )

Delegate to Container#define on the new namespace.

    # File lib/needle/definition-context.rb, line 69
69:     def namespace_define( *parms, &block )
70:       @container.namespace( *parms ) { |ns| ns.define( &block ) }
71:     end
namespace_define!( *parms, &block )
This method is also aliased as namespace!
    # File lib/needle/definition-context.rb, line 62
62:     def namespace_define!( *parms, &block )
63:       @container.namespace_define!( *parms, &block )
64:     end
require( *parms )

Delegate to Container#require on the current container.

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

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

    # File lib/needle/definition-context.rb, line 47
47:     def this_container
48:       @container
49:     end
use( opts, &block )

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
82:     def use( opts, &block )
83:       use! @container.defaults.merge( opts ), &block
84:     end
use!( opts ) {|self| ...}

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
 88:     def use!( opts )
 89:       original = @container.use!( opts )
 90: 
 91:       if block_given?
 92:         begin
 93:           yield self
 94:         ensure
 95:           @container.use! original
 96:         end
 97:       end
 98: 
 99:       original
100:     end