Sha256: ec450e7aebe3788e3c090e8bea4a6035e9c4fb5f0962b697ab4acdd9914e9254

Contents?: true

Size: 792 Bytes

Versions: 4

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

require 'dry/plugins/config'
require 'dry/plugins/registry'

module Dry
  module Plugins
    class Registry
      # Builds a {Registry} child class specific to `plugins` module
      # @see ClassBuilder#call
      class ClassBuilder
        # @param class_name [Symbol]
        def initialize(class_name: Plugins.config.registry_class_name)
          @class_name = class_name
        end

        # @return [Symbol]
        attr_reader :class_name

        # @param plugins [Module]
        #
        # @return [Class(Registry)]
        def call(plugins)
          unless plugins.const_defined? class_name
            plugins.const_set class_name, Class.new(Registry)
          end
          plugins.const_get class_name
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-plugins-0.4.0 lib/dry/plugins/registry/class_builder.rb
dry-plugins-0.3.0 lib/dry/plugins/registry/class_builder.rb
dry-plugins-0.2.0 lib/dry/plugins/registry/class_builder.rb
dry-plugins-0.1.0 lib/dry/plugins/registry/class_builder.rb