Class: Diggit::PluginLoader

Inherits:
Object
  • Object
show all
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:

Examples:

PluginLoader.instance

See Also:

Constant Summary collapse

PLUGINS_TYPES =
[:addon, :analysis, :join]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePluginLoader

Constructor. Should not be called directly. Use instance instead.



311
312
313
# File 'lib/dgit/core.rb', line 311

def initialize
  @plugins = {}
end

Class Method Details

.plugin_paths(name, type, root) ⇒ Object



305
306
307
# File 'lib/dgit/core.rb', line 305

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.

Parameters:

  • name (String)

    the name of the plugin

  • type (Symbol)

    the type of the plugin: :addon, :analysis or :join.

  • instance (Boolean) (defaults to: false)

    true for retrieving an instance or false for retrieving the class.

Returns:

  • (Plugin, Class)

    the instance or class of the plugin.



292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/dgit/core.rb', line 292

def load_plugin(name, type, instance = false)
  plugin = search_plugin(name, type)
  if plugin
    if instance
      return plugin.new(Dig.it.options)
    else
      return plugin
    end
  else
    fail "Plugin #{name} not found."
  end
end