Class: Dry::Plugins::Plugin Abstract
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Dry::Plugins::Plugin
- Extended by:
- Forwardable
- Defined in:
- lib/dry/plugins/plugin.rb
Overview
This class is abstract.
A delegator providing Plugin DSL
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#__getobj__ ⇒ Module
(also: #plugin)
Module with actual plugin data.
- #__setobj__(plugin) ⇒ Object (also: #plugin=)
- #call(host, &configuration) ⇒ <Symbol> (also: #plug)
- #config ⇒ Config
-
#configure(host, &configuration) ⇒ Object
Configure the
host
usingconfiguration
. -
#initialize(registry, name, plugin = nil) ⇒ Plugin
constructor
A new instance of Plugin.
-
#load ⇒ Module
Resolves the plug-in
Module
from the Registry. -
#load_dependencies(host) ⇒ Object
Load plugin and plugin dependencies (if declared).
Constructor Details
#initialize(registry, name, plugin) ⇒ Plugin #initialize(registry, plugin) ⇒ Plugin
Returns a new instance of Plugin.
21 22 23 24 25 26 27 |
# File 'lib/dry/plugins/plugin.rb', line 21 def initialize(registry, name, plugin = nil) @__registry__ = registry plugin = name if name.is_a?(Module) self.name = name self.plugin = plugin if plugin end |
Instance Attribute Details
#name ⇒ Symbol
52 53 54 |
# File 'lib/dry/plugins/plugin.rb', line 52 def name @name end |
Instance Method Details
#__getobj__ ⇒ Module Also known as: plugin
Module with actual plugin data
35 36 37 38 39 |
# File 'lib/dry/plugins/plugin.rb', line 35 def __getobj__ super do __setobj__ load end end |
#__setobj__(plugin) ⇒ Object Also known as: plugin=
44 45 46 47 |
# File 'lib/dry/plugins/plugin.rb', line 44 def __setobj__(plugin) self.name = plugin if plugin super(plugin) end |
#call(host, &configuration) ⇒ <Symbol> Also known as: plug
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dry/plugins/plugin.rb', line 65 def call(host, &configuration) load_dependencies(host) if plugin.const_defined?(Plugins.config.class_interface_name) host.extend(plugin.const_get(Plugins.config.class_interface_name)) end host.send(:include, plugin) configure(host, &configuration) if configuration host.used_plugins << name host end |
#config ⇒ Config
31 |
# File 'lib/dry/plugins/plugin.rb', line 31 def_delegators :@__registry__, :config |
#configure(host, &configuration) ⇒ Object
Configure the host
using configuration
95 96 97 98 99 100 |
# File 'lib/dry/plugins/plugin.rb', line 95 def configure(host, &configuration) if plugin.respond_to?(Plugins.config.configure_method) return plugin.public_send(Plugins.config.configure_method, host, &configuration) end host.module_eval(&configuration) end |
#load ⇒ Module
Resolves the plug-in Module
from the Registry
80 81 82 |
# File 'lib/dry/plugins/plugin.rb', line 80 def load @__registry__.resolve(name) end |
#load_dependencies(host) ⇒ Object
Load plugin and plugin dependencies (if declared)
87 88 89 90 |
# File 'lib/dry/plugins/plugin.rb', line 87 def load_dependencies(host) return unless plugin.respond_to?(Plugins.config.load_dependencies_method) plugin.public_send(Plugins.config.load_dependencies_method, host) end |