Class: Dry::Container::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/container/namespace.rb

Overview

Create a namespace to be imported

Examples:


ns = Dry::Container::Namespace.new('name') do
  register('item', 'item')
end

container = Dry::Container.new

container.import(ns)

container.resolve('name.item')
=> 'item'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) { ... } ⇒ Dry::Container::Namespace

Create a new namespace

Parameters:

  • name (Mixed)

    The name of the namespace

Yields:

  • The block to evaluate when the namespace is imported



38
39
40
41
# File 'lib/dry/container/namespace.rb', line 38

def initialize(name, &block)
  @name = name
  @block = block
end

Instance Attribute Details

#blockProc (readonly)

Returns The block to be executed when the namespace is imported.

Returns:

  • (Proc)

    The block to be executed when the namespace is imported



26
27
28
# File 'lib/dry/container/namespace.rb', line 26

def block
  @block
end

#nameMixed (readonly)

Returns The namespace (name).

Returns:

  • (Mixed)

    The namespace (name)



24
25
26
# File 'lib/dry/container/namespace.rb', line 24

def name
  @name
end