Class: Dry::System::Importer Private
- Inherits:
-
Object
- Object
- Dry::System::Importer
- 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.
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
- #container ⇒ Object readonly private
- #registry ⇒ Object readonly private
Instance Method Summary collapse
- #[](name) ⇒ Object private
- #finalize! ⇒ Object private
- #import(namespace, keys: Undefined) ⇒ Object private
-
#initialize(container) ⇒ Importer
constructor
private
A new instance of Importer.
- #key?(name) ⇒ Boolean (also: #namespace?) private
- #register(namespace:, container:, keys: nil) ⇒ Object private
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.
32 33 34 35 |
# File 'lib/dry/system/importer.rb', line 32 def initialize(container) @container = container @registry = {} end |
Instance Attribute Details
#container ⇒ Object (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.
27 28 29 |
# File 'lib/dry/system/importer.rb', line 27 def container @container end |
#registry ⇒ Object (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.
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.
47 48 49 |
# File 'lib/dry/system/importer.rb', line 47 def [](name) registry.fetch(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.
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.
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.
52 53 54 |
# File 'lib/dry/system/importer.rb', line 52 def key?(name) registry.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.
38 39 40 41 42 43 44 |
# File 'lib/dry/system/importer.rb', line 38 def register(namespace:, container:, keys: nil) registry[namespace] = Item.new( namespace: namespace, container: container, import_keys: keys ) end |