Class: Vedeu::Plugins Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

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

#pluginsArray<String> (protected)

Returns:

  • (Array<String>)


69
70
71
# File 'lib/vedeu/plugins/plugins.rb', line 69

def plugins
  @plugins
end

Instance Method Details

#findArray<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.

Returns:

  • (Array<void>)


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

#loadArray<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.

Returns:

  • (Array<void>)


21
22
23
# File 'lib/vedeu/plugins/plugins.rb', line 21

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

#namesHash

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.

Returns:

  • (Hash)


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.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



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

#prefixString (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:

  • (String)


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.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • plugin (Vedeu::Plugin) (defaults to: false)

Returns:

  • (Array<void>)


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