Class: Vedeu::Plugins
- Inherits:
-
Object
- Object
- Vedeu::Plugins
- Defined in:
- lib/vedeu/plugins/plugins.rb
Overview
A class responsible for managing plugins installation.
Instance Attribute Summary collapse
- #input ⇒ Array<String> readonly protected
- #plugins ⇒ Array<String> protected
Instance Method Summary collapse
-
#find ⇒ Array<void>
Find all installed plugins and store them.
-
#initialize ⇒ Vedeu::Plugins
constructor
Returns a new instance of Vedeu::Plugins.
-
#load ⇒ Array<void>
Loads all plugins that are not enabled.
-
#names ⇒ Hash
Return a list of all plugin names as strings.
-
#not_loaded?(name) ⇒ Boolean
private
Returns a boolean indicating whether a plugin is already loaded.
- #prefix ⇒ String private
-
#register(name, plugin = false) ⇒ Array<void>
Register plugin with name in an internal array.
Constructor Details
#initialize ⇒ Vedeu::Plugins
Returns a new instance of Vedeu::Plugins.
12 13 14 |
# File 'lib/vedeu/plugins/plugins.rb', line 12 def initialize @plugins = [] end |
Instance Attribute Details
#input ⇒ Array<String> (readonly, protected)
67 |
# File 'lib/vedeu/plugins/plugins.rb', line 67 attr_accessor :plugins |
#plugins ⇒ Array<String> (protected)
67 68 69 |
# File 'lib/vedeu/plugins/plugins.rb', line 67 def plugins @plugins end |
Instance Method Details
#find ⇒ Array<void>
Find all installed plugins and store them.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vedeu/plugins/plugins.rb', line 38 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>
Loads all plugins that are not enabled.
19 20 21 |
# File 'lib/vedeu/plugins/plugins.rb', line 19 def load plugins.each { |plugin| plugin.load! unless plugin.enabled? } end |
#names ⇒ Hash
Return a list of all plugin names as strings.
55 56 57 58 59 60 61 |
# File 'lib/vedeu/plugins/plugins.rb', line 55 def names collection = {} plugins.each_with_object(collection) do |hash, plugin| hash[plugin.name] = plugin hash end end |
#not_loaded?(name) ⇒ Boolean (private)
Returns a boolean indicating whether a plugin is already loaded.
75 76 77 |
# File 'lib/vedeu/plugins/plugins.rb', line 75 def not_loaded?(name) plugins.empty? || plugins.any? { |plugin| plugin.gem_name != name } end |
#prefix ⇒ String (private)
80 81 82 |
# File 'lib/vedeu/plugins/plugins.rb', line 80 def prefix 'vedeu_' end |
#register(name, plugin = false) ⇒ Array<void>
Register plugin with name in an internal array.
28 29 30 31 32 33 |
# File 'lib/vedeu/plugins/plugins.rb', line 28 def register(name, plugin = false) Vedeu.log(type: :debug, message: "Attempting to register plugin: #{name}") plugins << plugin if plugin && not_loaded?(name) end |