Class: Dry::Plugins::Registry::ClassBuilder

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

Overview

Builds a Dry::Plugins::Registry child class specific to plugins module

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name: Plugins.config.registry_class_name) ⇒ ClassBuilder

Returns a new instance of ClassBuilder.

Parameters:

  • class_name (Symbol) (defaults to: Plugins.config.registry_class_name)


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

def initialize(class_name: Plugins.config.registry_class_name)
  @class_name = class_name
end

Instance Attribute Details

#class_nameSymbol (readonly)

Returns:

  • (Symbol)


18
19
20
# File 'lib/dry/plugins/registry/class_builder.rb', line 18

def class_name
  @class_name
end

Instance Method Details

#call(plugins) ⇒ Class(Registry)

Parameters:

  • plugins (Module)

Returns:



23
24
25
26
27
28
# File 'lib/dry/plugins/registry/class_builder.rb', line 23

def call(plugins)
  unless plugins.const_defined? class_name
    plugins.const_set class_name, Class.new(Registry)
  end
  plugins.const_get class_name
end