Class: Nanoc::Int::PluginRegistry Private
- Inherits:
-
Object
- Object
- Nanoc::Int::PluginRegistry
- Extended by:
- Memoization
- Defined in:
- lib/nanoc/base/plugin_registry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The class responsible for keeping track of all loaded plugins, such as filters (Filter) and data sources (DataSource).
Defined Under Namespace
Modules: PluginMethods
Constant Summary
Constants included from Memoization
Class Method Summary collapse
-
.instance ⇒ Nanoc::Int::PluginRegistry
private
Returns the shared PluginRegistry instance, creating it if none exists yet.
Instance Method Summary collapse
-
#all ⇒ Array<Hash>
private
Returns a list of all plugins.
-
#find(klass, name) ⇒ Class?
private
Finds the plugin that is a subclass of the given class and has the given name.
-
#find_all(klass) ⇒ Enumerable<Class>
private
Returns all plugins of the given class.
-
#identifiers_of(superclass, klass) ⇒ Array<Symbol>
private
An array of identifiers for the given class.
-
#initialize ⇒ PluginRegistry
constructor
private
Creates a new plugin registry.
-
#register(superclass, class_or_name, *identifiers) ⇒ void
private
Registers the given class as a plugin.
Methods included from Memoization
Constructor Details
#initialize ⇒ PluginRegistry
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.
Creates a new plugin registry. This should usually not be necessary; it is recommended to use the shared instance (obtained from instance).
98 99 100 101 |
# File 'lib/nanoc/base/plugin_registry.rb', line 98 def initialize @identifiers_to_classes = {} @classes_to_identifiers = {} end |
Class Method Details
.instance ⇒ Nanoc::Int::PluginRegistry
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 shared Nanoc::Int::PluginRegistry instance, creating it if none exists yet.
91 92 93 |
# File 'lib/nanoc/base/plugin_registry.rb', line 91 def self.instance @instance ||= new end |
Instance Method Details
#all ⇒ Array<Hash>
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 a list of all plugins. The returned list of plugins is an array with array elements in the following format:
{ :class => ..., :superclass => ..., :identifiers => ... }
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/nanoc/base/plugin_registry.rb', line 168 def all plugins = [] @identifiers_to_classes.each_pair do |superclass, submap| submap.each_pair do |identifier, klass| # Find existing plugin existing_plugin = plugins.find do |p| p[:class] == klass && p[:superclass] == superclass end if existing_plugin # Add identifier to existing plugin existing_plugin[:identifiers] << identifier existing_plugin[:identifiers] = existing_plugin[:identifiers].sort_by(&:to_s) else # Create new plugin plugins << { class: klass, superclass: superclass, identifiers: [identifier], } end end end plugins end |
#find(klass, 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.
Finds the plugin that is a subclass of the given class and has the given name.
145 146 147 148 |
# File 'lib/nanoc/base/plugin_registry.rb', line 145 def find(klass, name) @identifiers_to_classes[klass] ||= {} resolve(@identifiers_to_classes[klass][name.to_sym], klass) end |
#find_all(klass) ⇒ Enumerable<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 the given class.
155 156 157 158 159 160 |
# File 'lib/nanoc/base/plugin_registry.rb', line 155 def find_all(klass) @identifiers_to_classes[klass] ||= {} res = {} @identifiers_to_classes[klass].each_pair { |k, v| res[k] = resolve(v, k) } res end |
#identifiers_of(superclass, klass) ⇒ Array<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.
Returns An array of identifiers for the given class.
133 134 135 |
# File 'lib/nanoc/base/plugin_registry.rb', line 133 def identifiers_of(superclass, klass) (@classes_to_identifiers[superclass] || {})[name_for_class(klass)] || [] end |
#register(superclass, 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.
117 118 119 120 121 122 123 124 125 |
# File 'lib/nanoc/base/plugin_registry.rb', line 117 def register(superclass, class_or_name, *identifiers) @identifiers_to_classes[superclass] ||= {} @classes_to_identifiers[superclass] ||= {} identifiers.each do |identifier| @identifiers_to_classes[superclass][identifier.to_sym] = class_or_name (@classes_to_identifiers[superclass][name_for_class(class_or_name)] ||= []) << identifier.to_sym end end |