Class: Dry::Plugins::ModuleBuilder

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

Overview

Builds a Module containing all plug-ins for host

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugins_module_name: Plugins.config.plugins_module_name) ⇒ ModuleBuilder

Returns a new instance of ModuleBuilder.



10
11
12
# File 'lib/dry/plugins/module_builder.rb', line 10

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

Instance Attribute Details

#plugins_module_nameSymbol (readonly)

Returns:

  • (Symbol)


15
16
17
# File 'lib/dry/plugins/module_builder.rb', line 15

def plugins_module_name
  @plugins_module_name
end

Instance Method Details

#call(host) ⇒ Module

Examples:

require 'dry/plugins/module_builder'

class Host
end

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

Parameters:

  • host (Module)

Returns:

  • (Module)


29
30
31
32
33
34
35
36
# File 'lib/dry/plugins/module_builder.rb', line 29

def call(host)
  plugins = if host.const_defined?(plugins_module_name)
              host.const_get(plugins_module_name)
            else
              host.const_set(plugins_module_name, Module.new)
            end
  plugins
end