diff --git a/lib/dry/system/importer.rb b/lib/dry/system/importer.rb index e1261ea9..c6000e92 100644 --- a/lib/dry/system/importer.rb +++ b/lib/dry/system/importer.rb @@ -36,7 +36,7 @@ def initialize(container) # @api private def register(namespace:, container:, keys: nil) - registry[namespace] = Item.new( + registry[namespace_key(namespace)] = Item.new( namespace: namespace, container: container, import_keys: keys @@ -45,12 +45,12 @@ def register(namespace:, container:, keys: nil) # @api private def [](name) - registry.fetch(name) + registry.fetch(namespace_key(name)) end # @api private def key?(name) - registry.key?(name) + registry.key?(namespace_key(name)) end alias_method :namespace?, :key? @@ -76,6 +76,17 @@ def import(namespace, keys: Undefined) private + # Returns nil if given a nil (i.e. root) namespace. Otherwise, converts the namespace to a + # string. + # + # This ensures imported components are found when either symbols or strings to given as the + # namespace in {Container.import}. + def namespace_key(namespace) + return nil if namespace.nil? + + namespace.to_s + end + def keys_to_import(keys, item) keys .then { (arr = item.import_keys) ? _1 & arr : _1 }