Sha256: c033c25dd627a89327b7d0947f5f6dfd5b68a0fd8a9d5e58d0f14a61b65cfb55

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require "rom/constants"

module ROM
  module Plugins
    # Plugin registration DSL
    #
    # @private
    class DSL
      # Default options passed to plugin registration
      #
      # @return [Hash]
      #
      # @api private
      attr_reader :defaults

      # Plugin registry
      #
      # @return [PluginRegistry]
      #
      # @api private
      attr_reader :registry

      # @api private
      def initialize(registry, defaults = EMPTY_HASH, &block)
        @registry = registry
        @defaults = defaults
        instance_exec(&block)
      end

      # Register a plugin
      #
      # @param [Symbol] name Name of a plugin
      # @param [Module] mod Plugin module
      # @param [Hash] options
      #
      # @api public
      def register(name, mod, options = EMPTY_HASH)
        registry.register(name, mod: mod, **defaults, **options)
      end

      # Register plugins for a specific adapter
      #
      # @param [Symbol] type The adapter identifier
      #
      # @api public
      def adapter(type, &block)
        self.class.new(registry, adapter: type, &block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-6.0.0.alpha1 lib/rom/plugins/dsl.rb