class Vagrant::Plugin::Remote::Manager

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.

Attributes

client[RW]

@return [VagrantPlugins::Command::Serve::Client::PluginManager] remote manager client

core_client[RW]

@return [VagrantPlugins::Command::Serve::Client::CorePluginManager] remote manager client for core plugins

Public Class Methods

new(*args, **kwargs, &block) click to toggle source
Calls superclass method
# File lib/vagrant/plugin/remote/manager.rb, line 63
def initialize(*args, **kwargs, &block)
  @logger = Log4r::Logger.new(self.class.name.downcase)
  kwargs[:client] = self.class.client
  super(*args, **kwargs, &block)
  kwargs.delete(:client)
  @init = [args, kwargs, block]
end

Public Instance Methods

inspect() click to toggle source

@return [String]

# File lib/vagrant/plugin/remote/manager.rb, line 77
def inspect
  "<#{self.class.name}:#{object_id} plugin_name=#{name} type=#{self.class.type}>"
end
method_missing(*args, **kwargs, &block) click to toggle source

If an unknown method is called on the plugin, this will check if the actual plugin is local to the Ruby runtime. If it is not, a NoMethodError will be generated. If it is, the local plugin will either be loaded from the cache or instantiated and the method call will be executed against the local plugin instance.

Calls superclass method
# File lib/vagrant/plugin/remote/manager.rb, line 91
def method_missing(*args, **kwargs, &block)
  klass = get_local_plugin
  return super if klass.nil?
  @logger.debug("found local plugin class #{self.class.name} -> #{klass.name}")
  c = VagrantPlugins::CommandServe.cache
  key = c.key(klass, *@init[0])
  if !c.registered?(key)
    @logger.debug("creating new local plugin instance of #{klass} with args: #{@init}")
    c.register(key, klass.new(*@init[0], **@init[1], &@init[2]))
  end
  @logger.debug("sending ##{args.first} result to local plugin #{klass}")
  c.get(key).send(*args, **kwargs, &block)
end
name() click to toggle source

@return [String] name of plugin

# File lib/vagrant/plugin/remote/manager.rb, line 72
def name
  self.class.plugin_name
end
to_s() click to toggle source

@return [String]

# File lib/vagrant/plugin/remote/manager.rb, line 82
def to_s
  "<#{self.class.name}:#{object_id}>"
end

Private Instance Methods

get_local_plugin() click to toggle source

@return [Class, NilClass] class of the local plugin

# File lib/vagrant/plugin/remote/manager.rb, line 108
def get_local_plugin
  m = ["#{self.class.type.downcase}s",
    "#{self.class.type.downcase}es"].detect { |i|
    Vagrant.plugin("2").local_manager.respond_to?(i)
  }
  if m.nil?
    @logger.debug("failed to locate valid local plugin registry method for plugin type #{self.class.type}")
    return
  end
  klass = Array(Vagrant.plugin("2").local_manager.
    send(m)[self.class.plugin_name.to_sym]).first
  @logger.trace("local plugin lookup for #{self.class.name} / #{self.class.plugin_name} / #{self.class.type}: #{klass}")
  klass
end