Module: Nanoc::Int::PluginRegistry::PluginMethods Private

Included in:
DataSource, Extra::Checking::Check, Extra::Deployer, Filter, ActionProvider
Defined in:
lib/nanoc/base/plugin_registry.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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

#allHash<Symbol, Class>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



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

def all
  Nanoc::Int::PluginRegistry.instance.find_all(self)
end

#identifier(identifier) ⇒ void #identifierSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overloads:

  • #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.

  • #identifierSymbol

    Returns The first identifier for this plugin.

    Returns:

    • (Symbol)

      The first identifier for this plugin



44
45
46
47
48
49
50
# 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) ⇒ void #identifiersArray<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overloads:

  • #identifiers(*identifiers) ⇒ void

    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.

  • #identifiersArray<Symbol>

    Returns The identifiers for this plugin.

    Returns:

    • (Array<Symbol>)

      The identifiers for this plugin



25
26
27
28
29
30
31
# 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) ⇒ Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



82
83
84
# 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) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



61
62
63
64
65
66
67
68
69
# 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