Module: Dry::System::Plugins

Included in:
Container
Defined in:
lib/dry/system/plugins.rb,
lib/dry/system/plugins/env.rb,
lib/dry/system/plugins/logging.rb,
lib/dry/system/plugins/bootsnap.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/dependency_graph/strategies.rb

Defined Under Namespace

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

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.



73
74
75
# File 'lib/dry/system/plugins.rb', line 73

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:



63
64
65
# File 'lib/dry/system/plugins.rb', line 63

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.



68
69
70
# File 'lib/dry/system/plugins.rb', line 68

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.



105
106
107
# File 'lib/dry/system/plugins.rb', line 105

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.



99
100
101
102
# File 'lib/dry/system/plugins.rb', line 99

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

#use(name, options = {}) ⇒ self

Enable a plugin

Plugin identifier

Parameters:

  • name (Symbol)

    The plugin identifier

  • options (Hash) (defaults to: {})

    Plugin options

Returns:

  • (self)


87
88
89
90
91
92
93
94
95
96
# File 'lib/dry/system/plugins.rb', line 87

def use(name, options = {})
  unless enabled_plugins.include?(name)
    plugin = Plugins.registry[name]
    plugin.load_dependencies
    plugin.apply_to(self, options)

    enabled_plugins << name
  end
  self
end