Module: DDPlugin::Plugin

Defined in:
lib/ddplugin/plugin.rb

Overview

A module that contains class methods for plugins. It provides functions for setting identifiers and finding plugins. Plugin classes should extend this module.

Instance Method Summary collapse

Instance Method Details

#allEnumerable<Class>

Returns All classes of this type.

Returns:

  • (Enumerable<Class>)

    All classes of this type



56
57
58
# File 'lib/ddplugin/plugin.rb', line 56

def all
  DDPlugin::Registry.instance.find_all(self)
end

#identifier(identifier) ⇒ void #identifierSymbol

Overloads:

  • #identifier(identifier) ⇒ void

    This method returns an undefined value.

    Sets the identifier for this class.

    Parameters:

    • identifier (Symbol, String)

      The identifier to assign to this class.

  • #identifierSymbol

    Returns The first identifier for this class.

    Returns:

    • (Symbol)

      The first identifier for this class



47
48
49
50
51
52
53
# File 'lib/ddplugin/plugin.rb', line 47

def identifier(identifier = nil)
  if identifier
    identifiers(identifier)
  else
    identifiers.first
  end
end

#identifiers(*identifiers) ⇒ void #identifiersArray<Symbol>

Overloads:

  • #identifiers(*identifiers) ⇒ void

    This method returns an undefined value.

    Sets the identifiers for this class.

    Parameters:

    • identifiers (Array<Symbol, String>)

      A list of identifiers to assign to this class.

  • #identifiersArray<Symbol>

    Returns The identifiers for this class.

    Returns:

    • (Array<Symbol>)

      The identifiers for this class



20
21
22
23
24
25
26
# File 'lib/ddplugin/plugin.rb', line 20

def identifiers(*identifiers)
  if identifiers.empty?
    DDPlugin::Registry.instance.identifiers_of(root_class, self)
  else
    DDPlugin::Registry.instance.register(root_class, self, *identifiers)
  end
end

#named(identifier) ⇒ Class

Returns The class with the given identifier.

Parameters:

  • identifier (Symbol, String)

    The identifier of the class to find

Returns:

  • (Class)

    The class with the given identifier



63
64
65
# File 'lib/ddplugin/plugin.rb', line 63

def named(identifier)
  DDPlugin::Registry.instance.find(self, identifier)
end

#root_classClass

Returns The root class for this class.

Returns:

  • (Class)

    The root class for this class



29
30
31
32
33
# File 'lib/ddplugin/plugin.rb', line 29

def root_class
  klass = self
  klass = klass.superclass while klass.superclass.respond_to?(:identifiers)
  klass
end