Class: Dry::Plugins::Registry
- Inherits:
-
Object
- Object
- Dry::Plugins::Registry
- Includes:
- Container::Mixin
- Defined in:
- lib/dry/plugins/registry.rb,
lib/dry/plugins/registry/builder.rb,
lib/dry/plugins/registry/resolver.rb,
lib/dry/plugins/registry/key_error.rb,
lib/dry/plugins/registry/load_error.rb,
lib/dry/plugins/registry/class_builder.rb
Overview
Plug-in Registry
Defined Under Namespace
Classes: Builder, ClassBuilder, KeyError, LoadError, Resolver
Instance Attribute Summary collapse
- #plugins ⇒ Module readonly
Instance Method Summary collapse
-
#initialize(plugins) ⇒ Registry
constructor
A new instance of Registry.
- #proxy(plugin, name: nil) ⇒ Plugin
- #register(key, plugin = nil) ⇒ Plugin
-
#resolve(name) ⇒ Plugin
(also: #[])
Resolve an item from the container.
Constructor Details
#initialize(plugins) ⇒ Registry
Returns a new instance of Registry.
22 23 24 25 26 |
# File 'lib/dry/plugins/registry.rb', line 22 def initialize(plugins) @require_path = Inflecto.underscore(plugins.to_s) @plugins = plugins super() end |
Instance Attribute Details
#plugins ⇒ Module (readonly)
29 30 31 |
# File 'lib/dry/plugins/registry.rb', line 29 def plugins @plugins end |
Instance Method Details
#proxy(plugin, name: nil) ⇒ Plugin
52 53 54 |
# File 'lib/dry/plugins/registry.rb', line 52 def proxy(plugin, name: nil) Plugin.new(self, name, plugin) end |
#register(key, plugin = nil) ⇒ Plugin
35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |