module Nanoc::Int::PluginRegistry::PluginMethods

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.

Public Instance Methods

all() click to toggle source

@return [Hash<Symbol, Class>] All plugins of this type, with keys

being the identifiers and values the plugin classes
# File lib/nanoc/base/plugin_registry.rb, line 73
def all
  Nanoc::Int::PluginRegistry.instance.find_all(self)
end
identifier(identifier = nil) click to toggle source

@overload identifier(identifier)

Sets the identifier for this plugin.

@param [Symbol] identifier An identifier to assign to this plugin.

@return [void]

@overload identifier

@return [Symbol] The first identifier for this plugin
# File lib/nanoc/base/plugin_registry.rb, line 44
def identifier(identifier = nil)
  if identifier
    identifiers(identifier)
  else
    Nanoc::Int::PluginRegistry.instance.identifiers_of(superclass, self).first
  end
end
identifiers(*identifiers) click to toggle source

@overload identifiers(*identifiers)

Sets the identifiers for this plugin.

@param [Array<Symbol>] identifiers A list of identifiers to assign to
  this plugin.

@return [void]

@overload identifiers

@return [Array<Symbol>] The identifiers for this plugin
# File lib/nanoc/base/plugin_registry.rb, line 25
def identifiers(*identifiers)
  if identifiers.empty?
    Nanoc::Int::PluginRegistry.instance.identifiers_of(superclass, self)
  else
    register(self, *identifiers)
  end
end
named(name) click to toggle source

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

# File lib/nanoc/base/plugin_registry.rb, line 82
def named(name)
  Nanoc::Int::PluginRegistry.instance.find(self, name)
end
register(class_or_name, *identifiers) click to toggle source

Registers the given class as a plugin with the given identifier.

@param [Class, String] class_or_name The class to register, or a

string containing the class name to register.

@param [Array<Symbol>] identifiers A list of identifiers to assign to

this plugin.

@return [void]

# File lib/nanoc/base/plugin_registry.rb, line 61
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)
end