Class: Lolcommits::PluginManager
- Inherits:
-
Object
- Object
- Lolcommits::PluginManager
- Defined in:
- lib/lolcommits/plugin_manager.rb
Constant Summary collapse
- GEM_NAME_PREFIX =
/^#{Lolcommits::GEM_NAME}-/
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Class Method Summary collapse
Instance Method Summary collapse
- #enabled_plugins_for(runner) ⇒ Object
-
#find_by_name(name) ⇒ Lolcommits::Plugin
Finds the first plugin matching name.
-
#initialize ⇒ PluginManager
constructor
A new instance of PluginManager.
-
#load_plugins ⇒ Object
find and require all plugins.
- #plugin_names ⇒ Object
Constructor Details
#initialize ⇒ PluginManager
Returns a new instance of PluginManager.
15 16 17 |
# File 'lib/lolcommits/plugin_manager.rb', line 15 def initialize @plugins = [] end |
Instance Attribute Details
#plugins ⇒ Object (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
.init ⇒ Object
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.
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_plugins ⇒ Object
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_names ⇒ Object
30 31 32 |
# File 'lib/lolcommits/plugin_manager.rb', line 30 def plugin_names @plugins.map(&:name).sort end |