lib/qonfig/plugins/registry.rb in qonfig-0.10.0 vs lib/qonfig/plugins/registry.rb in qonfig-0.11.0
- old
+ new
@@ -1,129 +1,125 @@
# frozen_string_literal: true
-module Qonfig
- module Plugins
- # @api private
- # @since 0.4.0
- class Registry
- # @return [void]
- #
- # @api private
- # @since 0.4.0
- def initialize
- @plugin_set = {}
- @access_lock = Mutex.new
- end
+# @api private
+# @since 0.4.0
+class Qonfig::Plugins::Registry
+ # @return [void]
+ #
+ # @api private
+ # @since 0.4.0
+ def initialize
+ @plugin_set = {}
+ @access_lock = Mutex.new
+ end
- # @param plugin_name [Symbol, String]
- # @return [Qonfig::Plugins::Abstract]
- #
- # @api private
- # @since 0.4.0
- def [](plugin_name)
- thread_safe { fetch(plugin_name) }
- end
+ # @param plugin_name [Symbol, String]
+ # @return [Qonfig::Plugins::Abstract]
+ #
+ # @api private
+ # @since 0.4.0
+ def [](plugin_name)
+ thread_safe { fetch(plugin_name) }
+ end
- # @param plugin_name [Symbol, String]
- # @param plugin_module [Qonfig::Plugins::Abstract]
- # @return [void]
- #
- # @api private
- # @since 0.4.0
- def register(plugin_name, plugin_module)
- thread_safe { apply(plugin_name, plugin_module) }
- end
- alias_method :[]=, :register
+ # @param plugin_name [Symbol, String]
+ # @param plugin_module [Qonfig::Plugins::Abstract]
+ # @return [void]
+ #
+ # @api private
+ # @since 0.4.0
+ def register(plugin_name, plugin_module)
+ thread_safe { apply(plugin_name, plugin_module) }
+ end
+ alias_method :[]=, :register
- # @return [Array<String>]
- #
- # @api private
- # @since 0.4.0
- def names
- thread_safe { plugin_names }
- end
+ # @return [Array<String>]
+ #
+ # @api private
+ # @since 0.4.0
+ def names
+ thread_safe { plugin_names }
+ end
- private
+ private
- # @return [Hash]
- #
- # @api private
- # @since 0.4.0
- attr_reader :plugin_set
+ # @return [Hash]
+ #
+ # @api private
+ # @since 0.4.0
+ attr_reader :plugin_set
- # @return [Mutex]
- #
- # @api private
- # @since 0.4.0
- attr_reader :access_lock
+ # @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
+ # @return [void]
+ #
+ # @api private
+ # @since 0.4.0
+ def thread_safe
+ access_lock.synchronize { yield if block_given? }
+ end
- # @return [Array<String>]
- #
- # @api private
- # @since 0.4.0
- def plugin_names
- plugin_set.keys
- end
+ # @return [Array<String>]
+ #
+ # @api private
+ # @since 0.4.0
+ def plugin_names
+ plugin_set.keys
+ end
- # @param plugin_name [String]
- # @return [Boolean]
- #
- # @api private
- # @since 0.4.0
- def registered?(plugin_name)
- plugin_set.key?(plugin_name)
- end
+ # @param plugin_name [String]
+ # @return [Boolean]
+ #
+ # @api private
+ # @since 0.4.0
+ def registered?(plugin_name)
+ plugin_set.key?(plugin_name)
+ end
- # @param plugin_name [Symbol, String]
- # @param plugin_module [Qonfig::Plugins::Abstract]
- # @return [void]
- #
- # @raise [Qonfig::AlreadyRegisteredPluginError]
- #
- # @api private
- # @since 0.4.0
- def apply(plugin_name, plugin_module)
- plugin_name = indifferently_accessable_plugin_name(plugin_name)
+ # @param plugin_name [Symbol, String]
+ # @param plugin_module [Qonfig::Plugins::Abstract]
+ # @return [void]
+ #
+ # @raise [Qonfig::AlreadyRegisteredPluginError]
+ #
+ # @api private
+ # @since 0.4.0
+ def apply(plugin_name, plugin_module)
+ plugin_name = indifferently_accessable_plugin_name(plugin_name)
- if registered?(plugin_name)
- raise Qonfig::AlreadyRegisteredPluginError, "#{plugin_name} plugin already exist"
- end
+ if registered?(plugin_name)
+ raise Qonfig::AlreadyRegisteredPluginError, "#{plugin_name} plugin already exist"
+ end
- plugin_set[plugin_name] = plugin_module
- end
+ plugin_set[plugin_name] = plugin_module
+ end
- # @param plugin_name [Symbol, String]
- # @return [Qonfig::Plugins::Abstract]
- #
- # @raise [Qonfig::UnregisteredPluginError]
- #
- # @api private
- # @since 0.4.0
- def fetch(plugin_name)
- plugin_name = indifferently_accessable_plugin_name(plugin_name)
+ # @param plugin_name [Symbol, String]
+ # @return [Qonfig::Plugins::Abstract]
+ #
+ # @raise [Qonfig::UnregisteredPluginError]
+ #
+ # @api private
+ # @since 0.4.0
+ def fetch(plugin_name)
+ plugin_name = indifferently_accessable_plugin_name(plugin_name)
- unless registered?(plugin_name)
- raise Qonfig::UnregisteredPluginError, "#{plugin_name} plugin is not registered"
- end
+ unless registered?(plugin_name)
+ raise Qonfig::UnregisteredPluginError, "#{plugin_name} plugin is not registered"
+ end
- plugin_set[plugin_name]
- end
+ plugin_set[plugin_name]
+ end
- # @param key [Symbol, String]
- # @return [String]
- #
- # @api private
- # @since 0.4.0
- def indifferently_accessable_plugin_name(plugin_name)
- plugin_name.to_s
- end
- end
+ # @param key [Symbol, String]
+ # @return [String]
+ #
+ # @api private
+ # @since 0.4.0
+ def indifferently_accessable_plugin_name(plugin_name)
+ plugin_name.to_s
end
end