# frozen_string_literal: true require 'dry/plugins/config' require 'dry/plugins/registry/load_error' require 'dry/container/resolver' require 'inflecto' module Dry module Plugins class Registry # Default resolver for resolving plugins from registry class Resolver < Dry::Container::Resolver # Resolve a plugin from the registry # # @param container [Concurrent::Hash] # The container # @param name [Mixed] # The name for the plugin you wish to resolve # # @raise [LoadError] # If the given plugin is not registered in the registry # # @return [Mixed] # # @api public # If the registered plugin already exists, use it. # Otherwise, require it and return it. # This raises a LoadError if such a plugin doesn't exist, or a LoadError if it exists but it does # not register itself correctly. def call(container, name, require_path) name = name.to_s unless container.key?(name) path = Inflecto.underscore(name).tr('.', '/') require "#{require_path}/#{path}" raise LoadError.new(name, self) unless container.key?(name) end super(container, name) end end end end end