Module: Nanoc::PluginRegistry::PluginMethods

Included in:
DataSource, Extra::Checking::Check, Extra::Deployer, Extra::VCS, Filter
Defined in:
lib/nanoc/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

- (Hash<Symbol, Class>) all

Returns All plugins of this type, with keys being the identifiers and values the plugin classes

Returns:

  • (Hash<Symbol, Class>)

    All plugins of this type, with keys being the identifiers and values the plugin classes



77
78
79
# File 'lib/nanoc/base/plugin_registry.rb', line 77

def all
  Nanoc::Plugin.find_all(self)
end

- (void) identifier(identifier) - (Symbol) identifier

Overloads:

  • - (void) identifier(identifier)

    This method returns an undefined value.

    Sets the identifier for this plugin.

    Parameters:

    • identifier (Symbol)

      An identifier to assign to this plugin.

  • - (Symbol) identifier

    Returns The first identifier for this plugin

    Returns:

    • (Symbol)

      The first identifier for this plugin



48
49
50
51
52
53
54
# File 'lib/nanoc/base/plugin_registry.rb', line 48

def identifier(identifier = nil)
  if identifier
    identifiers(identifier)
  else
    Nanoc::PluginRegistry.instance.identifiers_of(superclass, self).first
  end
end

- (void) identifiers(*identifiers) - (Array<Symbol>) identifiers

Overloads:

  • - (void) identifiers(*identifiers)

    This method returns an undefined value.

    Sets the identifiers for this plugin.

    Parameters:

    • identifiers (Array<Symbol>)

      A list of identifiers to assign to this plugin.

  • - (Array<Symbol>) identifiers

    Returns The identifiers for this plugin

    Returns:

    • (Array<Symbol>)

      The identifiers for this plugin



29
30
31
32
33
34
35
# File 'lib/nanoc/base/plugin_registry.rb', line 29

def identifiers(*identifiers)
  if identifiers.empty?
    Nanoc::PluginRegistry.instance.identifiers_of(superclass, self)
  else
    register(self, *identifiers)
  end
end

- (Class) named(name)

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



86
87
88
# File 'lib/nanoc/base/plugin_registry.rb', line 86

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

- (void) register(class_or_name, *identifiers)

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.



65
66
67
68
69
70
71
72
73
# File 'lib/nanoc/base/plugin_registry.rb', line 65

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

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