Class: Needle::Registry
Overview
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 ) }
= registry.
Instance Attribute Summary
Attributes inherited from Container
Class Method Summary collapse
-
.define(*parms, &block) ⇒ Object
Instantiate a new Registry (via #new) and immediately invoke #define using the given block.
-
.define!(*parms, &block) ⇒ Object
Instantiate a new Registry (via #new) and immediately invoke #define! using the given block.
Instance Method Summary collapse
-
#fullname ⇒ Object
Returns
nil. -
#initialize(opts = {}) {|_self| ... } ⇒ Registry
constructor
Instantiate a new Registry.
Methods inherited from Container
#[], #builder, #define, #define!, #find_definition, #has_key?, #intercept, #keys, #knows_key?, #method_missing, #namespace, #namespace_define, #namespace_define!, #pipeline, #register, #require, #respond_to?, #root
Constructor Details
#initialize(opts = {}) {|_self| ... } ⇒ Registry
Instantiate a new Registry. The options hash may include options used to initialize the logger factory. The logger factory options should be in another hash, keyed by the value :logs.
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" }
)
97 98 99 100 101 |
# File 'lib/needle/registry.rb', line 97 def initialize( opts={} ) super( nil, nil ) bootstrap( opts ) yield( self ) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Needle::Container
Class Method Details
.define(*parms, &block) ⇒ Object
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
71 72 73 74 |
# File 'lib/needle/registry.rb', line 71 def self.define( *parms, &block ) raise NeedleError, "needs a block" if block.nil? new( *parms ) { |reg| reg.define( &block ) } end |
.define!(*parms, &block) ⇒ Object
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
55 56 57 58 |
# File 'lib/needle/registry.rb', line 55 def self.define!( *parms, &block ) raise NeedleError, "needs a block" if block.nil? new( *parms ) { |reg| reg.define!( &block ) } end |
Instance Method Details
#fullname ⇒ Object
Returns nil. Registries are unnamed containers.
104 105 106 |
# File 'lib/needle/registry.rb', line 104 def fullname nil end |