Class: Needle::Registry

### Home Classes Methods

### In Files

- lib/needle/registry.rb

### Parent

Needle::Container

### Methods

- ::define
- ::define!
- ::new
- #fullname

### 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::Registry

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

### Public Class Methods

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

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
    def self.define( *parms, &block )
      raise NeedleError, "needs a block" if block.nil?
      new( *parms ) { |reg| reg.define( &block ) }
    end

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

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
    def self.define!( *parms, &block )
      raise NeedleError, "needs a block" if block.nil?
      new( *parms ) { |reg| reg.define!( &block ) }
    end

new( opts={} ) click to toggle source

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
    def initialize( opts={} )
      super( opts[:parent], opts[:name] )
      bootstrap( opts ) if parent.nil?
      yield( self ) if block_given?
    end

### Public Instance Methods

fullname() click to toggle source

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
    def fullname
      parent ? super : nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.