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/monitoring/proxy.rb

Defined Under Namespace

Modules: Bootsnap, 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.


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

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:


59
60
61
# File 'lib/dry/system/plugins.rb', line 59

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.


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

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.


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

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.


95
96
97
98
# File 'lib/dry/system/plugins.rb', line 95

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)

83
84
85
86
87
88
89
90
91
92
# File 'lib/dry/system/plugins.rb', line 83

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