Class: Vagrant::Plugin::V1::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/plugin/v1/manager.rb

Overview

This class maintains a list of all the registered plugins as well as provides methods that allow querying all registered components of those plugins as a single unit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.


12
13
14
15
# File 'lib/vagrant/plugin/v1/manager.rb', line 12

def initialize
  @logger = Log4r::Logger.new("vagrant::plugin::v1::manager")
  @registered = []
end

Instance Attribute Details

#registeredObject (readonly)

Returns the value of attribute registered.


10
11
12
# File 'lib/vagrant/plugin/v1/manager.rb', line 10

def registered
  @registered
end

Instance Method Details

#communicatorsHash

This returns all the registered communicators.

Returns:

  • (Hash)

20
21
22
23
24
25
26
27
28
# File 'lib/vagrant/plugin/v1/manager.rb', line 20

def communicators
  result = {}

  @registered.each do |plugin|
    result.merge!(plugin.communicator.to_hash)
  end

  result
end

#configHash

This returns all the registered configuration classes.

Returns:

  • (Hash)

33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant/plugin/v1/manager.rb', line 33

def config
  result = {}

  @registered.each do |plugin|
    plugin.config.each do |key, klass|
      result[key] = klass
    end
  end

  result
end

#config_upgrade_safeHash

This returns all the registered configuration classes that were marked as "upgrade safe."

Returns:

  • (Hash)

49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vagrant/plugin/v1/manager.rb', line 49

def config_upgrade_safe
  result = {}

  @registered.each do |plugin|
    configs = plugin.data[:config_upgrade_safe]
    if configs
      configs.each do |key|
        result[key] = plugin.config.get(key)
      end
    end
  end

  result
end

#guestsHash

This returns all the registered guests.

Returns:

  • (Hash)

67
68
69
70
71
72
73
74
75
# File 'lib/vagrant/plugin/v1/manager.rb', line 67

def guests
  result = {}

  @registered.each do |plugin|
    result.merge!(plugin.guest.to_hash)
  end

  result
end

#hostsHash

This returns all registered host classes.

Returns:

  • (Hash)

80
81
82
83
84
85
86
87
88
# File 'lib/vagrant/plugin/v1/manager.rb', line 80

def hosts
  hosts = {}

  @registered.each do |plugin|
    hosts.merge!(plugin.host.to_hash)
  end

  hosts
end

#providersHash

This returns all registered providers.

Returns:

  • (Hash)

93
94
95
96
97
98
99
100
101
# File 'lib/vagrant/plugin/v1/manager.rb', line 93

def providers
  providers = {}

  @registered.each do |plugin|
    providers.merge!(plugin.provider.to_hash)
  end

  providers
end

#register(plugin) ⇒ Object

This registers a plugin. This should NEVER be called by the public and should only be called from within Vagrant. Vagrant will automatically register V1 plugins when a name is set on the plugin.


107
108
109
110
111
112
# File 'lib/vagrant/plugin/v1/manager.rb', line 107

def register(plugin)
  if !@registered.include?(plugin)
    @logger.info("Registered plugin: #{plugin.name}")
    @registered << plugin
  end
end

#reset!Object

This clears out all the registered plugins. This is only used by unit tests and should not be called directly.


116
117
118
# File 'lib/vagrant/plugin/v1/manager.rb', line 116

def reset!
  @registered.clear
end

#unregister(plugin) ⇒ Object

This unregisters a plugin so that its components will no longer be used. Note that this should only be used for testing purposes.


122
123
124
125
126
127
# File 'lib/vagrant/plugin/v1/manager.rb', line 122

def unregister(plugin)
  if @registered.include?(plugin)
    @logger.info("Unregistered: #{plugin.name}")
    @registered.delete(plugin)
  end
end