Sha256: 31a54a73f5c7b3bd8da1aeb8018e58fee15f43410d42a9c5e2f38b03ef5511b7

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Qonfig
  # @api public
  # @since 0.4.0
  module Plugins
    # @since 0.4.0
    @plugin_registry = Registry.new
    # @since 0.4.0
    @access_lock = Mutex.new

    class << self
      # @param plugin_name [Symbol, String]
      # @return [void]
      #
      # @api public
      # @since 0.4.0
      def load(plugin_name)
        thread_safe { plugin_registry[plugin_name].load! }
      end

      # @return [Array<String>]
      #
      # @api public
      # @since 0.4.0
      def names
        thread_safe { plugin_registry.names }
      end

      # @param plugin_name [Symbol, String]
      # @return [void]
      #
      # @api private
      # @since 0.4.0
      def register_plugin(plugin_name, plugin_module)
        thread_safe { plugin_registry[plugin_name] = plugin_module }
      end

      private

      # @return [Qonfig::Plugins::Registry]
      #
      # @api private
      # @since 0.4.0
      attr_reader :plugin_registry

      # @return [Mutex]
      #
      # @api private
      # @since 0.4.0
      attr_reader :access_lock

      # @return [void]
      #
      # @api private
      # @since 0.4.0
      def thread_safe
        access_lock.synchronize { yield if block_given? }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
qonfig-0.10.0 lib/qonfig/plugins.rb
qonfig-0.9.0 lib/qonfig/plugins.rb
qonfig-0.8.0 lib/qonfig/plugins.rb
qonfig-0.7.0 lib/qonfig/plugins.rb
qonfig-0.6.0 lib/qonfig/plugins.rb
qonfig-0.5.0 lib/qonfig/plugins.rb
qonfig-0.4.0 lib/qonfig/plugins.rb