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.
10 11 12 |
# File 'lib/vedeu/plugins/plugins.rb', line 10 def initialize @plugins = [] end |
Instance Attribute Details
#input ⇒ Array<String> (readonly, protected)
65 |
# File 'lib/vedeu/plugins/plugins.rb', line 65 attr_accessor :plugins |
#plugins ⇒ Array<String> (protected)
65 66 67 |
# File 'lib/vedeu/plugins/plugins.rb', line 65 def plugins @plugins end |
Instance Method Details
#find ⇒ Array<void>
Find all installed plugins and store them.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vedeu/plugins/plugins.rb', line 36 def find Gem.refresh Gem::Specification.each do |gem| next unless gem.name =~ /^#{prefix}/.freeze 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.
17 18 19 |
# File 'lib/vedeu/plugins/plugins.rb', line 17 def load plugins.each { |plugin| plugin.load! unless plugin.enabled? } end |
#names ⇒ Hash
Return a list of all plugin names as strings.
53 54 55 56 57 58 59 |
# File 'lib/vedeu/plugins/plugins.rb', line 53 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.
73 74 75 |
# File 'lib/vedeu/plugins/plugins.rb', line 73 def not_loaded?(name) plugins.empty? || plugins.any? { |plugin| plugin.gem_name != name } end |
#prefix ⇒ String (private)
78 79 80 |
# File 'lib/vedeu/plugins/plugins.rb', line 78 def prefix 'vedeu_'.freeze end |
#register(name, plugin = false) ⇒ Array<void>
Register plugin with name in an internal array.
26 27 28 29 30 31 |
# File 'lib/vedeu/plugins/plugins.rb', line 26 def register(name, plugin = false) Vedeu.log(type: :debug, message: "Attempting to register plugin: #{name}".freeze) plugins << plugin if plugin && not_loaded?(name) end |