Class: Diggit::PluginLoader
- Inherits:
-
Object
- Object
- Diggit::PluginLoader
- Includes:
- Singleton
- Defined in:
- lib/dgit/core.rb
Overview
Class to handle loading of diggit plugins. Diggit plugins are defined in camel cased classes derived from Plugin. Their name is the underscore cased version of the class name (example MyPlugin becomes my_plugin). It uses a singleton pattern, so you have to create an instance like that:
Constant Summary collapse
- PLUGINS_TYPES =
i[addon analysis join].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ PluginLoader
constructor
Constructor.
-
#load_plugin(name, type, instance = false) ⇒ Plugin, Class
Load the plugin with the given name and type.
Constructor Details
#initialize ⇒ PluginLoader
Constructor. Should not be called directly. Use instance instead.
244 245 246 |
# File 'lib/dgit/core.rb', line 244 def initialize @plugins = {} end |
Class Method Details
.plugin_paths(name, type, root) ⇒ Object
238 239 240 |
# File 'lib/dgit/core.rb', line 238 def self.plugin_paths(name, type, root) Dir.glob(File.join(root, 'plugins', type.to_s, '**{,/*/**}', "#{name}.rb")) end |
Instance Method Details
#load_plugin(name, type, instance = false) ⇒ Plugin, Class
Load the plugin with the given name and type.
231 232 233 234 235 236 |
# File 'lib/dgit/core.rb', line 231 def load_plugin(name, type, instance = false) plugin = search_plugin(name, type) raise "Plugin #{name} not found." unless plugin return plugin.new(Dig.it.) if instance plugin end |