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>)


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

attr_accessor :plugins

#pluginsArray<String> (protected)

Returns:

  • (Array<String>)


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

def plugins
  @plugins
end

Instance Method Details

#findArray<void>

Find all installed plugins and store them.

Returns:

  • (Array<void>)


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

#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)


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.

Parameters:

  • name (String)

Returns:

  • (Boolean)


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

#prefixString (private)

Returns:

  • (String)


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.

Parameters:

Returns:

  • (Array<void>)


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