Module: Vagrant::Hosts

Defined in:
lib/vagrant/hosts.rb,
lib/vagrant/hosts/bsd.rb,
lib/vagrant/hosts/arch.rb,
lib/vagrant/hosts/base.rb,
lib/vagrant/hosts/linux.rb,
lib/vagrant/hosts/fedora.rb,
lib/vagrant/hosts/gentoo.rb,
lib/vagrant/hosts/freebsd.rb,
lib/vagrant/hosts/windows.rb,
lib/vagrant/hosts/opensuse.rb

Defined Under Namespace

Classes: Arch, BSD, Base, Fedora, FreeBSD, Gentoo, Linux, OpenSUSE, Windows

Class Method Summary collapse

Class Method Details

.detect(registry) ⇒ Object

This method detects the correct host based on the match? methods implemented in the registered hosts.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant/hosts.rb', line 17

def self.detect(registry)
  logger = Log4r::Logger.new("vagrant::hosts")

  # Sort the hosts by their precedence
  host_klasses = registry.to_hash.values
  host_klasses = host_klasses.sort_by { |a| a.precedence }.reverse
  logger.debug("Host path search classes: #{host_klasses.inspect}")

  # Test for matches and return the host class that matches
  host_klasses.each do |klass|
    if klass.match?
      logger.info("Host class: #{klass}")
      return klass
    end
  end

  # No matches found...
  return nil
end