Class: Dry::System::Importer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/system/importer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Default importer implementation

This is currently configured by default for every System::Container. Importer objects are responsible for importing components from one container to another. This is used in cases where an application is split into multiple sub-systems.

API:

  • private

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container) ⇒ Importer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Importer.

API:

  • private



32
33
34
35
# File 'lib/dry/system/importer.rb', line 32

def initialize(container)
  @container = container
  @registry = {}
end

Instance Attribute Details

#containerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



27
28
29
# File 'lib/dry/system/importer.rb', line 27

def container
  @container
end

#registryObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



29
30
31
# File 'lib/dry/system/importer.rb', line 29

def registry
  @registry
end

Instance Method Details

#[](name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



47
48
49
# File 'lib/dry/system/importer.rb', line 47

def [](name)
  registry.fetch(namespace_key(name))
end

#finalize!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



58
59
60
61
# File 'lib/dry/system/importer.rb', line 58

def finalize!
  registry.each_key { import(_1) }
  self
end

#import(namespace, keys: Undefined) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dry/system/importer.rb', line 64

def import(namespace, keys: Undefined)
  item = self[namespace]
  keys = Undefined.default(keys, item.import_keys)

  if keys
    import_keys(item.container, namespace, keys_to_import(keys, item))
  else
    import_all(item.container, namespace)
  end

  self
end

#key?(name) ⇒ Boolean Also known as: namespace?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

API:

  • private



52
53
54
# File 'lib/dry/system/importer.rb', line 52

def key?(name)
  registry.key?(namespace_key(name))
end

#register(namespace:, container:, keys: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



38
39
40
41
42
43
44
# File 'lib/dry/system/importer.rb', line 38

def register(namespace:, container:, keys: nil)
  registry[namespace_key(namespace)] = Item.new(
    namespace: namespace,
    container: container,
    import_keys: keys
  )
end