module Dry::System::Plugins
Public Class Methods
loaded_dependencies()
click to toggle source
@api private
# File lib/dry/system/plugins.rb, line 80 def self.loaded_dependencies @loaded_dependencies ||= [] end
register(name, plugin, &block)
click to toggle source
Register a plugin
@param [Symbol] name The name of a plugin @param [Class] plugin Plugin
module
@return [Plugins]
@api public
# File lib/dry/system/plugins.rb, line 70 def self.register(name, plugin, &block) registry[name] = Plugin.new(name, plugin, &block) end
registry()
click to toggle source
@api private
# File lib/dry/system/plugins.rb, line 75 def self.registry @registry ||= {} end
Public Instance Methods
enabled_plugins()
click to toggle source
@api private
# File lib/dry/system/plugins.rb, line 115 def enabled_plugins @enabled_plugins ||= [] end
inherited(klass)
click to toggle source
@api private
Calls superclass method
# File lib/dry/system/plugins.rb, line 109 def inherited(klass) klass.instance_variable_set(:@enabled_plugins, enabled_plugins.dup) super end
use(name, options = {})
click to toggle source
Enables a plugin if not already enabled. Raises error if plugin cannot be found in the plugin registry.
Plugin
identifier
@param [Symbol] name The plugin identifier @param [Hash] options Plugin
options
@return [self]
@api public
# File lib/dry/system/plugins.rb, line 95 def use(name, options = {}) return self if enabled_plugins.include?(name) raise PluginNotFoundError, name unless (plugin = Plugins.registry[name]) plugin.load_dependencies plugin.apply_to(self, options) enabled_plugins << name self end