Class: Dry::Plugins::Host::Builder

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

Overview

Extends a host with plug-ins interfaces

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry_method: Plugins.config.registry_method) ⇒ Builder

Returns a new instance of Builder.



11
12
13
# File 'lib/dry/plugins/host/builder.rb', line 11

def initialize(registry_method: Plugins.config.registry_method)
  @registry_method = registry_method
end

Instance Attribute Details

#registry_methodSymbol (readonly)

Returns:

  • (Symbol)


16
17
18
# File 'lib/dry/plugins/host/builder.rb', line 16

def registry_method
  @registry_method
end

Instance Method Details

#call(host, registry) ⇒ Module

Examples:

require 'dry/plugins/module_builder'

class Host
end

module_builder = Dry::Plugins::HostExtender.new
module_builder.call(Host) #=> Host::Plugins

Parameters:

  • host (Module)

Returns:

  • (Module)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dry/plugins/host/builder.rb', line 30

def call(host, registry)
  unless host.respond_to? registry_method
    host.define_singleton_method registry_method do
      registry
    end
  end

  unless host.singleton_class.included_modules.include? Host::DSL
    host.extend Host::DSL
  end

  host
end