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

Delegates to Container#has_key?.

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

Delegate to Container#intercept.

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

Delegates to Container#knows_key?.

     # File lib/needle/definition-context.rb, line 107
107:     def knows_key?( name )
108:       @container.knows_key?( name )
109:     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 118
118:     def method_missing( sym, *args, &block )
119:       if block.nil?
120:         @container.get( sym, *args )
121:       else
122:         @container.register( sym, *args, &block )
123:       end
124:     end
namespace( *parms, &block )

Delegate to Container#namespace.

    # File lib/needle/definition-context.rb, line 56
56:     def namespace( *parms, &block )
57:       @container.namespace( *parms, &block )
58:     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 68
68:     def namespace_define( *parms, &block )
69:       @container.namespace( *parms ) { |ns| ns.define( &block ) }
70:     end
namespace_define!( *parms, &block )
This method is also aliased as namespace!
    # File lib/needle/definition-context.rb, line 61
61:     def namespace_define!( *parms, &block )
62:       @container.namespace_define!( *parms, &block )
63:     end
require( *parms )

Delegate to Container#require on the current container.

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

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

    # File lib/needle/definition-context.rb, line 46
46:     def this_container
47:       @container
48:     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 81
81:     def use( opts, &block )
82:       use! @container.defaults.merge( opts ), &block
83:     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 87
87:     def use!( opts )
88:       original = @container.use!( opts )
89: 
90:       if block_given?
91:         begin
92:           yield self
93:         ensure
94:           @container.use! original
95:         end
96:       end
97: 
98:       original
99:     end