Class: Vedeu::Plugins

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/plugins/plugins.rb

Overview

A class responsible for managing plugins installation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVedeu::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

#inputArray<String> (readonly, protected)

Returns:

  • (Array<String>)


64
# File 'lib/vedeu/plugins/plugins.rb', line 64

attr_accessor :plugins

#pluginsArray<String> (protected)

Returns:

  • (Array<String>)


64
65
66
# File 'lib/vedeu/plugins/plugins.rb', line 64

def plugins
  @plugins
end

Instance Method Details

#findArray<void>

Find all installed plugins and store them.

Returns:

  • (Array<void>)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vedeu/plugins/plugins.rb', line 35

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

#loadArray<void>

Loads all plugins that are not enabled.

Returns:

  • (Array<void>)


17
18
19
# File 'lib/vedeu/plugins/plugins.rb', line 17

def load
  plugins.each { |plugin| plugin.load! unless plugin.enabled? }
end

#namesHash

Return a list of all plugin names as strings.

Returns:

  • (Hash)


52
53
54
55
56
57
58
# File 'lib/vedeu/plugins/plugins.rb', line 52

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.

Parameters:

  • name (String)

Returns:

  • (Boolean)


72
73
74
# File 'lib/vedeu/plugins/plugins.rb', line 72

def not_loaded?(name)
  plugins.empty? || plugins.any? { |plugin| plugin.gem_name != name }
end

#prefixString (private)

Returns:

  • (String)


77
78
79
# File 'lib/vedeu/plugins/plugins.rb', line 77

def prefix
  'vedeu_'
end

#register(name, plugin = false) ⇒ Array<void>

Register plugin with name in an internal array.

Parameters:

Returns:

  • (Array<void>)


26
27
28
29
30
# File 'lib/vedeu/plugins/plugins.rb', line 26

def register(name, plugin = false)
  Vedeu.log(type: :debug, message: "Attempting to register plugin: #{name}")

  plugins << plugin if plugin && not_loaded?(name)
end