Class: Vedeu::Plugins Private
- Inherits:
-
Object
- Object
- Vedeu::Plugins
- Defined in:
- lib/vedeu/plugins/plugins.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.
A class responsible for managing plugins installation.
Instance Attribute Summary collapse
- #plugins ⇒ Array<String> protected
Instance Method Summary collapse
-
#find ⇒ Array<void>
private
Find all installed plugins and store them.
-
#initialize ⇒ Vedeu::Plugins
constructor
private
Returns a new instance of Vedeu::Plugins.
-
#load ⇒ Array<void>
private
Loads all plugins that are not enabled.
-
#names ⇒ Hash
private
Return a list of all plugin names as strings.
-
#not_loaded?(name) ⇒ Boolean
private
private
Returns a boolean indicating whether a plugin is already loaded.
- #prefix ⇒ String private private
-
#register(name, plugin = false) ⇒ Array<void>
private
Register plugin with name in an internal array.
Constructor Details
#initialize ⇒ Vedeu::Plugins
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 new instance of Vedeu::Plugins.
14 15 16 |
# File 'lib/vedeu/plugins/plugins.rb', line 14 def initialize @plugins = [] end |
Instance Attribute Details
#plugins ⇒ Array<String> (protected)
69 70 71 |
# File 'lib/vedeu/plugins/plugins.rb', line 69 def plugins @plugins end |
Instance Method Details
#find ⇒ Array<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.
Find all installed plugins and store them.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vedeu/plugins/plugins.rb', line 40 def find Gem.refresh Gem::Specification.each do |gem| next unless gem.name =~ /^#{prefix}/ plugin_name = gem.name[/^#{prefix}(.*)/, 1] register(plugin_name, Vedeu::Plugin.new(plugin_name, gem)) end plugins end |
#load ⇒ Array<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.
Loads all plugins that are not enabled.
21 22 23 |
# File 'lib/vedeu/plugins/plugins.rb', line 21 def load plugins.each { |plugin| plugin.load! unless plugin.enabled? } end |
#names ⇒ 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.
Return a list of all plugin names as strings.
57 58 59 60 61 62 63 |
# File 'lib/vedeu/plugins/plugins.rb', line 57 def names collection = {} plugins.each_with_object(collection) do |hash, plugin| hash[plugin.name] = plugin hash end end |
#not_loaded?(name) ⇒ Boolean (private)
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 boolean indicating whether a plugin is already loaded.
77 78 79 |
# File 'lib/vedeu/plugins/plugins.rb', line 77 def not_loaded?(name) plugins.empty? || plugins.any? { |plugin| plugin.gem_name != name } end |
#prefix ⇒ String (private)
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.
82 83 84 |
# File 'lib/vedeu/plugins/plugins.rb', line 82 def prefix 'vedeu_' end |
#register(name, plugin = false) ⇒ Array<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.
Register plugin with name in an internal array.
30 31 32 33 34 35 |
# File 'lib/vedeu/plugins/plugins.rb', line 30 def register(name, plugin = false) Vedeu.log(type: :debug, message: "Attempting to register plugin: #{name}") plugins << plugin if plugin && not_loaded?(name) end |