Class: Dry::Plugins::Registry::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/plugins/registry/builder.rb

Overview

Build a plug-in registry for given host

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry_method: Plugins.config.registry_method, **kwargs) ⇒ Builder

Returns a new instance of Builder.



13
14
15
16
# File 'lib/dry/plugins/registry/builder.rb', line 13

def initialize(registry_method: Plugins.config.registry_method, **kwargs)
  @registry_method = registry_method
  super(**kwargs)
end

Instance Attribute Details

#registry_methodSymbol (readonly)

Returns:

  • (Symbol)


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

def registry_method
  @registry_method
end

Instance Method Details

#call(host, plugins: module_builder.call(host), registry_class: class_builder.call(plugins)) ⇒ Registry

Parameters:

  • plugins (Module) (defaults to: module_builder.call(host))

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dry/plugins/registry/builder.rb', line 24

def call(host,
         plugins: module_builder.call(host),
         registry_class: class_builder.call(plugins))
  unless plugins.respond_to? registry_method
    registry_variable = :"@#{registry_method}"
    plugins.define_singleton_method registry_method do
      if instance_variable_defined? registry_variable
        instance_variable_get registry_variable
      else
        instance_variable_set registry_variable, registry_class.new(plugins)
      end
    end
  end

  unless plugins.singleton_class.included_modules.include? DSL
    plugins.extend DSL
  end

  plugins.public_send registry_method
end