lib/nanoc/base/plugin_registry.rb in nanoc-4.3.0 vs lib/nanoc/base/plugin_registry.rb in nanoc-4.3.1

- old
+ new

@@ -22,11 +22,12 @@ # @overload identifiers # # @return [Array<Symbol>] The identifiers for this plugin def identifiers(*identifiers) if identifiers.empty? - Nanoc::Int::PluginRegistry.instance.identifiers_of(superclass, self) + registry = Nanoc::Int::PluginRegistry.instance + registry.identifiers_of(registry.root_class_of(self), self) else register(self, *identifiers) end end @@ -43,11 +44,12 @@ # @return [Symbol] The first identifier for this plugin def identifier(identifier = nil) if identifier identifiers(identifier) else - Nanoc::Int::PluginRegistry.instance.identifiers_of(superclass, self).first + registry = Nanoc::Int::PluginRegistry.instance + registry.identifiers_of(registry.root_class_of(self), self).first end end # Registers the given class as a plugin with the given identifier. # @@ -57,17 +59,13 @@ # @param [Array<Symbol>] identifiers A list of identifiers to assign to # this plugin. # # @return [void] def register(class_or_name, *identifiers) - # Find plugin class - klass = self - klass = klass.superclass while klass.superclass.respond_to?(:register) - - # Register registry = Nanoc::Int::PluginRegistry.instance - registry.register(klass, class_or_name, *identifiers) + root = registry.root_class_of(self) + registry.register(root, 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 @@ -155,9 +153,20 @@ def find_all(klass) @identifiers_to_classes[klass] ||= {} res = {} @identifiers_to_classes[klass].each_pair { |k, v| res[k] = resolve(v, k) } res + end + + # @param [Class] klass + # + # @return [Class] + # + # @api private + def root_class_of(subclass) + root_class = subclass + root_class = root_class.superclass while root_class.superclass.respond_to?(:register) + root_class end # Returns a list of all plugins. The returned list of plugins is an array # with array elements in the following format: #