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



74
75
76
# File 'lib/nanoc/base/plugin_registry.rb', line 74

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



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

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



26
27
28
29
30
31
32
# File 'lib/nanoc/base/plugin_registry.rb', line 26

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



83
84
85
# File 'lib/nanoc/base/plugin_registry.rb', line 83

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.



62
63
64
65
66
67
68
69
70
# File 'lib/nanoc/base/plugin_registry.rb', line 62

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