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.



15
16
17
18
# File 'lib/vagrant/plugin/v1/manager.rb', line 15

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

Instance Attribute Details

#registeredObject (readonly)

Returns the value of attribute registered.



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

def registered
  @registered
end

Instance Method Details

#communicatorsHash

This returns all the registered communicators.

Returns:

  • (Hash)


23
24
25
26
27
28
29
30
31
# File 'lib/vagrant/plugin/v1/manager.rb', line 23

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)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vagrant/plugin/v1/manager.rb', line 36

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)


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

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)


70
71
72
73
74
75
76
77
78
# File 'lib/vagrant/plugin/v1/manager.rb', line 70

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)


83
84
85
86
87
88
89
90
91
# File 'lib/vagrant/plugin/v1/manager.rb', line 83

def hosts
  hosts = {}

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

  hosts
end

#providersHash

This returns all registered providers.

Returns:

  • (Hash)


96
97
98
99
100
101
102
103
104
# File 'lib/vagrant/plugin/v1/manager.rb', line 96

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.



110
111
112
113
114
115
# File 'lib/vagrant/plugin/v1/manager.rb', line 110

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.



119
120
121
# File 'lib/vagrant/plugin/v1/manager.rb', line 119

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.



125
126
127
128
129
130
# File 'lib/vagrant/plugin/v1/manager.rb', line 125

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