Module: Nanoc3::PluginRegistry::PluginMethods

Included in:
DataSource, Extra::VCS, Filter
Defined in:
lib/nanoc3/base/plugin_registry.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#identifier(identifier) ⇒ void

This method returns an undefined value.

Sets the identifier for this plugin.

Parameters:

  • identifier (Symbol)

    An identifier to assign to this plugin.



30
31
32
# File 'lib/nanoc3/base/plugin_registry.rb', line 30

def identifier(identifier)
  register(self, identifier)
end

#identifiers(*identifiers) ⇒ void

This method returns an undefined value.

Sets the identifiers for this plugin.

Parameters:

  • identifier (Array<Symbol>)

    A list of identifiers to assign to this plugin.



21
22
23
# File 'lib/nanoc3/base/plugin_registry.rb', line 21

def identifiers(*identifiers)
  register(self, *identifiers)
end

#named(name) ⇒ Class

Returns the plugin with the given name (identifier)

Parameters:

  • name (String)

    The name of the plugin class to find

Returns:

  • (Class)

    The plugin class with the given name



58
59
60
# File 'lib/nanoc3/base/plugin_registry.rb', line 58

def named(name)
  Nanoc3::Plugin.find(self, name)
end

#register(class_or_name, *identifiers) ⇒ void

This method returns an undefined value.

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

Parameters:

  • class_or_name (Class, String)

    The class to register, or a string containing the class name to register.

  • identifiers (Array<Symbol>)

    A list of identifiers to assign to this plugin.



43
44
45
46
47
48
49
50
51
# File 'lib/nanoc3/base/plugin_registry.rb', line 43

def register(class_or_name, *identifiers)
  # Find plugin class
  klass = self
  klass = klass.superclass while klass.superclass.respond_to?(:register)

  # Register
  registry = Nanoc3::PluginRegistry.instance
  registry.register(klass, class_or_name, *identifiers)
end