Class: Vagrant::Plugin::V2::Manager
- Inherits:
-
Object
- Object
- Vagrant::Plugin::V2::Manager
- 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
-
#registered ⇒ Object
readonly
Returns the value of attribute registered.
Instance Method Summary collapse
-
#action_hooks(hook_name) ⇒ Array
This returns all the action hooks.
-
#commands ⇒ Registry<Symbol, Array<Proc, Hash>>
This returns all the registered commands.
-
#communicators ⇒ Hash
This returns all the registered communicators.
-
#config ⇒ Hash
This returns all the registered configuration classes.
-
#find_action_hooks(key) ⇒ Array<Proc>
Find all hooks that are applicable for the given key.
-
#generate_hook_keys(key) ⇒ Array<String>
Generate all valid lookup keys for given key.
-
#guest_capabilities ⇒ Hash
This returns all the registered guest capabilities.
-
#guests ⇒ Hash
This returns all the registered guests.
-
#host_capabilities ⇒ Hash
This returns all the registered host capabilities.
-
#hosts ⇒ Hash
This returns all the registered guests.
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
-
#provider_capabilities ⇒ Hash
This returns all the registered provider capabilities.
-
#provider_configs ⇒ Hash
This returns all the config classes for the various providers.
-
#providers ⇒ Hash
This returns all registered providers.
-
#provisioner_configs ⇒ Registry
This returns all the config classes for the various provisioners.
-
#provisioners ⇒ Hash
This returns all registered provisioners.
-
#push_configs ⇒ Registry
This returns all the config classes for the various pushes.
-
#pushes ⇒ Registry
This returns all registered pushes.
-
#register(plugin) ⇒ Object
This registers a plugin.
-
#reset! ⇒ Object
This clears out all the registered plugins.
-
#synced_folder_capabilities ⇒ Hash
This returns all the registered synced folder capabilities.
-
#synced_folders ⇒ Registry
This returns all synced folder implementations.
-
#unregister(plugin) ⇒ Object
This unregisters a plugin so that its components will no longer be used.
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
15 16 17 18 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 15 def initialize @logger = Log4r::Logger.new("vagrant::plugin::v2::manager") @registered = [] end |
Instance Attribute Details
#registered ⇒ Object (readonly)
Returns the value of attribute registered.
13 14 15 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 13 def registered @registered end |
Instance Method Details
#action_hooks(hook_name) ⇒ Array
This returns all the action hooks.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 23 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 |
#commands ⇒ Registry<Symbol, Array<Proc, Hash>>
This returns all the registered commands.
90 91 92 93 94 95 96 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 90 def commands Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.components.commands) end end end |
#communicators ⇒ Hash
This returns all the registered communicators.
101 102 103 104 105 106 107 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 101 def communicators Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.communicator) end end end |
#config ⇒ Hash
This returns all the registered configuration classes.
112 113 114 115 116 117 118 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 112 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"]
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 52 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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 69 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_capabilities ⇒ Hash
This returns all the registered guest capabilities.
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 134 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 |
#guests ⇒ Hash
This returns all the registered guests.
123 124 125 126 127 128 129 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 123 def guests Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.components.guests) end end end |
#host_capabilities ⇒ Hash
This returns all the registered host capabilities.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 160 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 |
#hosts ⇒ Hash
This returns all the registered guests.
149 150 151 152 153 154 155 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 149 def hosts Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.components.hosts) end end end |
#provider_capabilities ⇒ Hash
This returns all the registered provider capabilities.
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 186 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_configs ⇒ Hash
This returns all the config classes for the various providers.
201 202 203 204 205 206 207 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 201 def provider_configs Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.components.configs[:provider]) end end end |
#providers ⇒ Hash
This returns all registered providers.
175 176 177 178 179 180 181 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 175 def providers Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.components.providers) end end end |
#provisioner_configs ⇒ Registry
This returns all the config classes for the various provisioners.
212 213 214 215 216 217 218 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 212 def provisioner_configs Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.components.configs[:provisioner]) end end end |
#provisioners ⇒ Hash
This returns all registered provisioners.
223 224 225 226 227 228 229 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 223 def provisioners Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.provisioner) end end end |
#push_configs ⇒ Registry
This returns all the config classes for the various pushes.
245 246 247 248 249 250 251 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 245 def push_configs Registry.new.tap do |result| @registered.each do |plugin| result.merge!(plugin.components.configs[:push]) end end end |
#pushes ⇒ Registry
This returns all registered pushes.
234 235 236 237 238 239 240 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 234 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.
282 283 284 285 286 287 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 282 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.
291 292 293 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 291 def reset! @registered.clear end |
#synced_folder_capabilities ⇒ Hash
This returns all the registered synced folder capabilities.
267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 267 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_folders ⇒ Registry
This returns all synced folder implementations.
256 257 258 259 260 261 262 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 256 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.
297 298 299 300 301 302 |
# File 'lib/vagrant/plugin/v2/manager.rb', line 297 def unregister(plugin) if @registered.include?(plugin) @logger.info("Unregistered: #{plugin.name}") @registered.delete(plugin) end end |