Skip to content

Commit

Permalink
Fix finding root class in PluginRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Aug 21, 2016
1 parent 43fd291 commit 39a0c5a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/nanoc/base/plugin_registry.rb
Expand Up @@ -24,7 +24,8 @@ module PluginMethods
# @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
Expand All @@ -45,7 +46,8 @@ 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

Expand All @@ -59,13 +61,9 @@ def identifier(identifier = nil)
#
# @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
Expand Down Expand Up @@ -159,6 +157,17 @@ def find_all(klass)
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:
#
Expand Down
29 changes: 29 additions & 0 deletions spec/nanoc/base/plugin_registry_spec.rb
@@ -0,0 +1,29 @@
describe Nanoc::Int::PluginRegistry do
describe '.identifier(s)' do
let(:identifier) { :ce79f6b8ddb22233e9aaf7d8f011689492acf02f }

context 'direct subclass' do
example do
klass =
Class.new(Nanoc::Filter) do
identifier :plugin_registry_spec
end

expect(klass.identifier).to eql(:plugin_registry_spec)
end
end

context 'indirect subclass' do
example do
superclass = Class.new(Nanoc::Filter)

klass =
Class.new(superclass) do
identifier :plugin_registry_spec
end

expect(klass.identifier).to eql(:plugin_registry_spec)
end
end
end
end
5 changes: 5 additions & 0 deletions spec/nanoc/regressions/gh_928_spec.rb
@@ -0,0 +1,5 @@
describe 'GH-928', site: true, stdio: true do
example do
expect { Nanoc::CLI.run(%w(check --list)) }.to output(%r{^ css$}).to_stdout
end
end

0 comments on commit 39a0c5a

Please sign in to comment.