Class: Lolcommits::PluginManager

Inherits:
Object
  • Object
show all
Defined in:
lib/lolcommits/plugin_manager.rb

Constant Summary collapse

GEM_NAME_PREFIX =
/^#{Lolcommits::GEM_NAME}-/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePluginManager

Returns a new instance of PluginManager.



15
16
17
# File 'lib/lolcommits/plugin_manager.rb', line 15

def initialize
  @plugins = []
end

Instance Attribute Details

#pluginsObject (readonly)

Returns the value of attribute plugins.



13
14
15
# File 'lib/lolcommits/plugin_manager.rb', line 13

def plugins
  @plugins
end

Class Method Details

.initObject



7
8
9
10
11
# File 'lib/lolcommits/plugin_manager.rb', line 7

def self.init
  pm = new
  pm.load_plugins
  pm
end

Instance Method Details

#enabled_plugins_for(runner) ⇒ Object



34
35
36
37
38
39
# File 'lib/lolcommits/plugin_manager.rb', line 34

def enabled_plugins_for(runner)
  @plugins.map do |gem_plugin|
    plugin = gem_plugin.plugin_instance(runner)
    plugin.enabled? ? plugin : nil
  end.compact
end

#find_by_name(name) ⇒ Lolcommits::Plugin

Returns finds the first plugin matching name.

Returns:



26
27
28
# File 'lib/lolcommits/plugin_manager.rb', line 26

def find_by_name(name)
  @plugins.find { |plugin| plugin.name =~ /^#{name}/ } unless name.empty?
end

#load_pluginsObject

find and require all plugins



20
21
22
23
# File 'lib/lolcommits/plugin_manager.rb', line 20

def load_plugins
  find_plugins
  @plugins.map(&:activate!)
end

#plugin_namesObject



30
31
32
# File 'lib/lolcommits/plugin_manager.rb', line 30

def plugin_names
  @plugins.map(&:name).sort
end