Registry is a specialization of Container, with additional functionality for bootstrapping basic services into a new registry. It also supports a define! method for easily registering new services.

Usage:

  require 'needle'

  registry = Needle::Registry.new
  registry.register( :foo ) { Foo.new }
  registry.register( :bar ) { |c| Bar.new( c.foo ) }

  bar = registry.bar
Methods
Public Class methods
define( *parms, &block )

Instantiate a new Registry (via new) and immediately invoke define using the given block.

Usage:

  registry = Needle::Registry.define do |b|
    b.add { Adder.new }
    ...
  end

  adder = registry.add
    # File lib/needle/registry.rb, line 74
74:     def self.define( *parms, &block )
75:       raise NeedleError, "needs a block" if block.nil?
76:       new( *parms ) { |reg| reg.define( &block ) }
77:     end
define!( *parms, &block )

Instantiate a new Registry (via new) and immediately invoke define! using the given block.

Usage:

  registry = Needle::Registry.define! do
    add { Adder.new }
    ...
  end

  adder = registry.add
    # File lib/needle/registry.rb, line 58
58:     def self.define!( *parms, &block )
59:       raise NeedleError, "needs a block" if block.nil?
60:       new( *parms ) { |reg| reg.define!( &block ) }
61:     end
new( opts={} ) {|self| ...}

Instantiate a new Registry. The options hash may include the following keys:

:logs:options used to initialize the logger factory. The value to this key should be another hash.
:parent:The parent container of this registry.
:name:The name of this registry.

If a block is given, the constructed registry instance is yielded to it.

Usage:

  registry = Needle::Registry.new

or

  registry = Needle::Registry.new do |reg|
    reg.register( :add ) { Adder.new }
  end

or

  registry = Needle::Registry.new(
    :logs => { :filename => "/dev/null" }
  )
     # File lib/needle/registry.rb, line 104
104:     def initialize( opts={} )
105:       super( opts[:parent], opts[:name] )
106:       bootstrap( opts ) if parent.nil?
107:       yield( self ) if block_given?
108:     end
Public Instance methods
fullname()

Returns nil, unless the registry has a parent, in which case it acts like Container#fullname. Registries are usually unnamed containers.

     # File lib/needle/registry.rb, line 112
112:     def fullname
113:       parent ? super : nil
114:     end