lib/nanoc/base/plugin_registry.rb in nanoc-3.8.0 vs lib/nanoc/base/plugin_registry.rb in nanoc-4.0.0a1

- old
+ new

@@ -1,13 +1,14 @@ # encoding: utf-8 -module Nanoc +module Nanoc::Int # The class responsible for keeping track of all loaded plugins, such as - # filters ({Nanoc::Filter}), data sources ({Nanoc::DataSource}) and VCSes - # ({Nanoc::Extra::VCS}). + # filters ({Nanoc::Filter}) and data sources ({Nanoc::DataSource}). + # + # @api private class PluginRegistry - extend Nanoc::Memoization + extend Nanoc::Int::Memoization # A module that contains class methods for plugins. It provides functions # for setting identifiers, registering plugins and finding plugins. Plugin # classes should extend this module. module PluginMethods @@ -23,11 +24,11 @@ # @overload identifiers # # @return [Array<Symbol>] The identifiers for this plugin def identifiers(*identifiers) if identifiers.empty? - Nanoc::PluginRegistry.instance.identifiers_of(superclass, self) + Nanoc::Int::PluginRegistry.instance.identifiers_of(superclass, self) else register(self, *identifiers) end end @@ -44,11 +45,11 @@ # @return [Symbol] The first identifier for this plugin def identifier(identifier = nil) if identifier identifiers(identifier) else - Nanoc::PluginRegistry.instance.identifiers_of(superclass, self).first + Nanoc::Int::PluginRegistry.instance.identifiers_of(superclass, self).first end end # Registers the given class as a plugin with the given identifier. # @@ -63,50 +64,50 @@ # Find plugin class klass = self klass = klass.superclass while klass.superclass.respond_to?(:register) # Register - registry = Nanoc::PluginRegistry.instance + registry = Nanoc::Int::PluginRegistry.instance registry.register(klass, class_or_name, *identifiers) end # @return [Hash<Symbol, Class>] All plugins of this type, with keys # being the identifiers and values the plugin classes def all - Nanoc::Plugin.find_all(self) + Nanoc::Int::PluginRegistry.instance.find_all(self) end # Returns the plugin with the given name (identifier) # # @param [String] name The name of the plugin class to find # # @return [Class] The plugin class with the given name def named(name) - Nanoc::Plugin.find(self, name) + Nanoc::Int::PluginRegistry.instance.find(self, name) end end # Returns the shared {PluginRegistry} instance, creating it if none exists # yet. # - # @return [Nanoc::PluginRegistry] The shared plugin registry + # @return [Nanoc::Int::PluginRegistry] The shared plugin registry def self.instance @instance ||= new end # Creates a new plugin registry. This should usually not be necessary; it # is recommended to use the shared instance (obtained from - # {Nanoc::PluginRegistry.instance}). + # {Nanoc::Int::PluginRegistry.instance}). def initialize @identifiers_to_classes = {} @classes_to_identifiers = {} end # Registers the given class as a plugin. # # @param [Class] superclass The superclass of the plugin. For example: - # {Nanoc::Filter}, {Nanoc::Extra::VCS}. + # {Nanoc::Filter}. # # @param [Class, String] class_or_name The class to register. This can be # a string, in which case it will be automatically converted to a proper # class at lookup. For example: `Nanoc::Filters::ERB`, # `"Nanoc::Filters::Haml"`. @@ -124,11 +125,11 @@ (@classes_to_identifiers[superclass][name_for_class(class_or_name)] ||= []) << identifier.to_sym end end # @param [Class] superclass The superclass of the plugin. For example: - # {Nanoc::Filter}, {Nanoc::Extra::VCS}. + # {Nanoc::Filter}. # # @param [Class] klass The class to get the identifiers for. # # @return [Array<Symbol>] An array of identifiers for the given class def identifiers_of(superclass, klass) @@ -191,15 +192,10 @@ end plugins end - # @deprecated Use {Nanoc::PluginRegistry#find} instead - def named(name) - find(self, name) - end - protected def resolve(class_or_name, _klass) if class_or_name.is_a?(String) class_or_name.scan(/\w+/).reduce(Kernel) do |memo, part| @@ -213,9 +209,6 @@ def name_for_class(klass) klass.to_s.sub(/^(::)?/, '::') end end - - # @deprecated Use {Nanoc::PluginRegistry.instance} instead - Plugin = PluginRegistry.instance end