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

#commandsRegistry<Symbol, Array<Proc, Hash>>

This returns all the registered commands.

Returns:


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

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

#communicatorsHash

This returns all the registered communicators.

Returns:

  • (Hash)

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

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)

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

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

#find_action_hooks(key) ⇒ Array<Proc>

Find all hooks that are applicable for the given key. This lookup does not include hooks which are defined for ALL_ACTIONS. Key lookups will match on either string or symbol values. The provided keys is broken down into multiple parts for lookups, which allows defining hooks with an entire namespaced name, or a short suffx. For example:

Assume we are given an action class key = Vagrant::Action::Builtin::SyncedFolders

The list of keys that will be checked for hooks: ["Vagrant::Action::Builtin::SyncedFolders", "vagrant_action_builtin_synced_folders", "Action::Builtin::SyncedFolders", "action_builtin_synced_folders", "Builtin::SyncedFolders", "builtin_synced_folders", "SyncedFolders", "synced_folders"]

Parameters:

  • key (Class, String)

    key Key for hook lookups

Returns:

  • (Array<Proc>)

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

def find_action_hooks(key)
  result = []

  generate_hook_keys(key).each do |k|
    @registered.each do |plugin|
      result += plugin.components.action_hooks[k]
      result += plugin.components.action_hooks[k.to_sym]
    end
  end

  result
end

#generate_hook_keys(key) ⇒ Array<String>

Generate all valid lookup keys for given key

Parameters:

  • key (Class, String)

    Base key for generation

Returns:

  • (Array<String>)

    all valid keys


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vagrant/plugin/v2/manager.rb', line 66

def generate_hook_keys(key)
  if key.is_a?(Class)
    key = key.name.to_s
  else
    key = key.to_s
  end
  parts = key.split("::")
  [].tap do |keys|
    until parts.empty?
      x = parts.join("::")
      keys << x
      y = x.gsub(/([a-z])([A-Z])/, '\1_\2').gsub('::', '_').downcase
      keys << y if x != y
      parts.shift
    end
  end
end

#guest_capabilitiesHash

This returns all the registered guest capabilities.

Returns:

  • (Hash)

131
132
133
134
135
136
137
138
139
140
141
# File 'lib/vagrant/plugin/v2/manager.rb', line 131

def guest_capabilities
  results = Hash.new { |h, k| h[k] = Registry.new }

  @registered.each do |plugin|
    plugin.components.guest_capabilities.each do |guest, caps|
      results[guest].merge!(caps)
    end
  end

  results
end

#guestsHash

This returns all the registered guests.

Returns:

  • (Hash)

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

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

#host_capabilitiesHash

This returns all the registered host capabilities.

Returns:

  • (Hash)

157
158
159
160
161
162
163
164
165
166
167
# File 'lib/vagrant/plugin/v2/manager.rb', line 157

def host_capabilities
  results = Hash.new { |h, k| h[k] = Registry.new }

  @registered.each do |plugin|
    plugin.components.host_capabilities.each do |host, caps|
      results[host].merge!(caps)
    end
  end

  results
end

#hostsHash

This returns all the registered guests.

Returns:

  • (Hash)

146
147
148
149
150
151
152
# File 'lib/vagrant/plugin/v2/manager.rb', line 146

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

#provider_capabilitiesHash

This returns all the registered provider capabilities.

Returns:

  • (Hash)

183
184
185
186
187
188
189
190
191
192
193
# File 'lib/vagrant/plugin/v2/manager.rb', line 183

def provider_capabilities
  results = Hash.new { |h, k| h[k] = Registry.new }

  @registered.each do |plugin|
    plugin.components.provider_capabilities.each do |provider, caps|
      results[provider].merge!(caps)
    end
  end

  results
end

#provider_configsHash

This returns all the config classes for the various providers.

Returns:

  • (Hash)

198
199
200
201
202
203
204
# File 'lib/vagrant/plugin/v2/manager.rb', line 198

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)

172
173
174
175
176
177
178
# File 'lib/vagrant/plugin/v2/manager.rb', line 172

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

#provisioner_configsRegistry

This returns all the config classes for the various provisioners.

Returns:


209
210
211
212
213
214
215
# File 'lib/vagrant/plugin/v2/manager.rb', line 209

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)

220
221
222
223
224
225
226
# File 'lib/vagrant/plugin/v2/manager.rb', line 220

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

#push_configsRegistry

This returns all the config classes for the various pushes.

Returns:


242
243
244
245
246
247
248
# File 'lib/vagrant/plugin/v2/manager.rb', line 242

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

#pushesRegistry

This returns all registered pushes.

Returns:


231
232
233
234
235
236
237
# File 'lib/vagrant/plugin/v2/manager.rb', line 231

def pushes
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.components.pushes)
    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.


279
280
281
282
283
284
# File 'lib/vagrant/plugin/v2/manager.rb', line 279

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.


288
289
290
# File 'lib/vagrant/plugin/v2/manager.rb', line 288

def reset!
  @registered.clear
end

#synced_folder_capabilitiesHash

This returns all the registered synced folder capabilities.

Returns:

  • (Hash)

264
265
266
267
268
269
270
271
272
273
274
# File 'lib/vagrant/plugin/v2/manager.rb', line 264

def synced_folder_capabilities
  results = Hash.new { |h, k| h[k] = Registry.new }

  @registered.each do |plugin|
    plugin.components.synced_folder_capabilities.each do |synced_folder, caps|
      results[synced_folder].merge!(caps)
    end
  end

  results
end

#synced_foldersRegistry

This returns all synced folder implementations.

Returns:


253
254
255
256
257
258
259
# File 'lib/vagrant/plugin/v2/manager.rb', line 253

def synced_folders
  Registry.new.tap do |result|
    @registered.each do |plugin|
      result.merge!(plugin.components.synced_folders)
    end
  end
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.


294
295
296
297
298
299
# File 'lib/vagrant/plugin/v2/manager.rb', line 294

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