Class: Vagrant::Plugin::V1::Manager
- Inherits:
-
Object
- Object
- Vagrant::Plugin::V1::Manager
- 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
-
#registered ⇒ Object
readonly
Returns the value of attribute registered.
Instance Method Summary collapse
-
#communicators ⇒ Hash
This returns all the registered communicators.
-
#config ⇒ Hash
This returns all the registered configuration classes.
-
#config_upgrade_safe ⇒ Hash
This returns all the registered configuration classes that were marked as “upgrade safe.”.
-
#guests ⇒ Hash
This returns all the registered guests.
-
#hosts ⇒ Hash
This returns all registered host classes.
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
-
#providers ⇒ Hash
This returns all registered providers.
-
#register(plugin) ⇒ Object
This registers a plugin.
-
#reset! ⇒ Object
This clears out all the registered plugins.
-
#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.
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
#registered ⇒ Object (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
#communicators ⇒ Hash
This returns all the registered communicators.
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 |
#config ⇒ Hash
This returns all the registered configuration classes.
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_safe ⇒ Hash
This returns all the registered configuration classes that were marked as “upgrade safe.”
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 |
#guests ⇒ Hash
This returns all the registered guests.
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 |
#hosts ⇒ Hash
This returns all registered host classes.
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 |
#providers ⇒ Hash
This returns all registered providers.
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 |