Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/dry/system/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?

Expand All @@ -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 }
Expand Down