module DDPlugin::Plugin

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

Public Instance Methods

all() click to toggle source

@return [Enumerable<Class>] All classes of this type

# File lib/ddplugin/plugin.rb, line 56
def all
  DDPlugin::Registry.instance.find_all(self)
end
identifier(identifier = nil) click to toggle source

@overload identifier(identifier)

Sets the identifier for this class.

@param [Symbol, String] identifier The identifier to assign to this
  class.

@return [void]

@overload identifier

@return [Symbol] The first identifier for this class
# File lib/ddplugin/plugin.rb, line 47
def identifier(identifier = nil)
  if identifier
    identifiers(identifier)
  else
    identifiers.first
  end
end
identifiers(*identifiers) click to toggle source

@overload identifiers(*identifiers)

Sets the identifiers for this class.

@param [Array<Symbol, String>] identifiers A list of identifiers to
  assign to this class.

@return [void]

@overload identifiers

@return [Array<Symbol>] The identifiers for this class
# 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) click to toggle source

@param [Symbol, String] identifier The identifier of the class to find

@return [Class] The class with the given identifier

# File lib/ddplugin/plugin.rb, line 63
def named(identifier)
  DDPlugin::Registry.instance.find(self, identifier)
end
root_class() click to toggle source

@return [Class] The root class for this class

# File lib/ddplugin/plugin.rb, line 29
def root_class
  klass = self
  klass = klass.superclass while klass.superclass.respond_to?(:identifiers)
  klass
end