Sha256: 7f80e63f6740c22eb99338024b55256dd94a3f27c2bba28fcc0d9fc91234fad4

Contents?: true

Size: 980 Bytes

Versions: 3

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

require 'rom/initializer'
require 'rom/constants'
require 'rom/support/configurable'

module ROM
  # Plugin is a simple object used to store plugin configurations
  #
  # @private
  class Plugin
    extend Initializer
    include Configurable

    # @!attribute [r] name
    #   @return [Symbol] plugin name
    # @api private
    param :name

    # @!attribute [r] mod
    #   @return [Module] a module representing the plugin
    # @api private
    param :mod

    # @!attribute [r] type
    #   @return [Symbol] plugin type
    # @api private
    option :type

    # Apply this plugin to the target
    #
    # @param [Class,Object] target
    #
    # @api private
    def apply_to(target, options = EMPTY_HASH)
      if mod.respond_to?(:apply)
        mod.apply(target, options)
      elsif mod.respond_to?(:new)
        target.include(mod.new(options))
      elsif target.is_a?(::Module)
        target.include(mod)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-core-5.1.2 lib/rom/plugin.rb
rom-core-5.1.1 lib/rom/plugin.rb
rom-core-5.1.0 lib/rom/plugin.rb