Module: Dry::System::Plugins

Included in:
Container
Defined in:
lib/dry/system/plugins.rb,
lib/dry/system/plugins/env.rb,
lib/dry/system/plugins/plugin.rb,
lib/dry/system/plugins/logging.rb,
lib/dry/system/plugins/bootsnap.rb,
lib/dry/system/plugins/zeitwerk.rb,
lib/dry/system/plugins/monitoring.rb,
lib/dry/system/plugins/notifications.rb,
lib/dry/system/plugins/dependency_graph.rb,
lib/dry/system/plugins/monitoring/proxy.rb,
lib/dry/system/plugins/zeitwerk/compat_inflector.rb,
lib/dry/system/plugins/dependency_graph/strategies.rb

Defined Under Namespace

Modules: Bootsnap, DependencyGraph, Logging, Monitoring, Notifications Classes: Env, Plugin, Zeitwerk

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.loaded_dependenciesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/dry/system/plugins.rb', line 24

def self.loaded_dependencies
  @loaded_dependencies ||= []
end

.register(name, plugin, &block) ⇒ Plugins

Register a plugin

Parameters:

  • name (Symbol)

    The name of a plugin

  • plugin (Class)

    Plugin module

Returns:



14
15
16
# File 'lib/dry/system/plugins.rb', line 14

def self.register(name, plugin, &block)
  registry[name] = Plugin.new(name, plugin, &block)
end

.registryObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/dry/system/plugins.rb', line 19

def self.registry
  @registry ||= {}
end

Instance Method Details

#enabled_pluginsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
# File 'lib/dry/system/plugins.rb', line 57

def enabled_plugins
  @enabled_plugins ||= []
end

#inherited(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
54
# File 'lib/dry/system/plugins.rb', line 51

def inherited(klass)
  klass.instance_variable_set(:@enabled_plugins, enabled_plugins.dup)
  super
end

#use(name, **options) ⇒ self

Enables a plugin if not already enabled. Raises error if plugin cannot be found in the plugin registry.

Parameters:

  • name (Symbol)

    The plugin name

  • options (Hash)

    Plugin options

Returns:

  • (self)

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dry/system/plugins.rb', line 37

def use(name, **options)
  return self if enabled_plugins.include?(name)

  raise PluginNotFoundError, name unless (plugin = Dry::System::Plugins.registry[name])

  plugin.load_dependencies
  plugin.apply_to(self, **options)

  enabled_plugins << name

  self
end