Module: Vagrant::Hosts

Defined in:
lib/vagrant/hosts.rb

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.

Parameters:

  • registry (Hash)

    Hash mapping key to host class



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant/hosts.rb', line 9

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

  # Sort the hosts by their precedence
  host_klasses = registry.values.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