Class: Vagrant::Plugin::V2::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/plugin/v2/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/v2/manager.rb', line 12

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

Instance Attribute Details

#registeredObject (readonly)

Returns the value of attribute registered.



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

def registered
  @registered
end

Instance Method Details

#action_hooks(hook_name) ⇒ Array

This returns all the action hooks.

Returns:

  • (Array)


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

def action_hooks(hook_name)
  result = []

  @registered.each do |plugin|
    result += plugin.components.action_hooks[Plugin::ALL_ACTIONS]
    result += plugin.components.action_hooks[hook_name]
  end

  result
end

#commandsHash

This returns all the registered commands.

Returns:

  • (Hash)


34
35
36
37
38
39
40
# File 'lib/vagrant/plugin/v2/manager.rb', line 34

def commands
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.command)
    end
  end
end

#communicatorsHash

This returns all the registered communicators.

Returns:

  • (Hash)


45
46
47
48
49
50
51
# File 'lib/vagrant/plugin/v2/manager.rb', line 45

def communicators
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.communicator)
    end
  end
end

#configHash

This returns all the registered configuration classes.

Returns:

  • (Hash)


56
57
58
59
60
61
62
# File 'lib/vagrant/plugin/v2/manager.rb', line 56

def config
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.components.configs[:top])
    end
  end
end

#guestsHash

This returns all the registered guests.

Returns:

  • (Hash)


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

def guests
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.guest)
    end
  end
end

#hostsHash

This returns all registered host classes.

Returns:

  • (Hash)


78
79
80
81
82
83
84
# File 'lib/vagrant/plugin/v2/manager.rb', line 78

def hosts
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.host)
    end
  end
end

#provider_configsHash

This returns all the config classes for the various providers.

Returns:

  • (Hash)


100
101
102
103
104
105
106
# File 'lib/vagrant/plugin/v2/manager.rb', line 100

def provider_configs
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.components.configs[:provider])
    end
  end
end

#providersHash

This returns all registered providers.

Returns:

  • (Hash)


89
90
91
92
93
94
95
# File 'lib/vagrant/plugin/v2/manager.rb', line 89

def providers
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.provider)
    end
  end
end

#provisioner_configsRegistry

This returns all the config classes for the various provisioners.

Returns:



111
112
113
114
115
116
117
# File 'lib/vagrant/plugin/v2/manager.rb', line 111

def provisioner_configs
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.components.configs[:provisioner])
    end
  end
end

#provisionersHash

This returns all registered provisioners.

Returns:

  • (Hash)


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

def provisioners
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.provisioner)
    end
  end
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 V2 plugins when a name is set on the plugin.



134
135
136
137
138
139
# File 'lib/vagrant/plugin/v2/manager.rb', line 134

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.



143
144
145
# File 'lib/vagrant/plugin/v2/manager.rb', line 143

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.



149
150
151
152
153
154
# File 'lib/vagrant/plugin/v2/manager.rb', line 149

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