class Dry::Plugins::Registry

Plug-in Registry

Attributes

plugins[R]

@return [Module]

Public Class Methods

new(plugins) click to toggle source

@param plugins [Module]

Calls superclass method
# File lib/dry/plugins/registry.rb, line 22
def initialize(plugins)
  @require_path = Inflecto.underscore(plugins.to_s)
  @plugins = plugins
  super()
end

Public Instance Methods

proxy(plugin, name: nil) click to toggle source

@param plugin [Module] @param name [Symbol]

@return [Plugin]

# File lib/dry/plugins/registry.rb, line 52
def proxy(plugin, name: nil)
  Plugin.new(self, name, plugin)
end
register(key, plugin = nil) click to toggle source

@param key [#to_sym] @param plugin [Module, Plugin]

@return [Plugin]

Calls superclass method
# File lib/dry/plugins/registry.rb, line 35
def register(key, plugin = nil)
  if key.is_a?(Module)
    plugin = key
    key = Inflecto.underscore(Inflecto.demodulize(plugin.name))
  end
  key = key.to_s
  plugin = plugin.plugin if plugin.is_a? Plugin
  if key?(key) && resolve(key) != plugin
    raise Registry::KeyError.new(self, key, plugin)
  end
  super key, plugin
end
resolve(name) click to toggle source

Resolve an item from the container

@param name [Mixed]

The key for the item you wish to resolve

@return [Plugin]

@api public

# File lib/dry/plugins/registry.rb, line 64
def resolve(name)
  registry = self
  plugin = config.resolver.call(_container, name, @require_path)
  Plugin.new(registry, name, plugin)
end