From 04a5e6bcd24d2b184dafd2a3ca74a23634680d28 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Jan 2014 18:34:19 -0800 Subject: [PATCH] core: Remove Vagrant::Hosts and add Vagrant::Host, a CapabilityHost --- lib/vagrant.rb | 2 +- lib/vagrant/host.rb | 16 ++++++++++++++ lib/vagrant/hosts.rb | 28 ------------------------- lib/vagrant/plugin/v2/host.rb | 15 ++----------- test/unit/vagrant/host_test.rb | 17 +++++++++++++++ test/unit/vagrant/hosts_test.rb | 37 --------------------------------- 6 files changed, 36 insertions(+), 79 deletions(-) create mode 100644 lib/vagrant/host.rb delete mode 100644 lib/vagrant/hosts.rb create mode 100644 test/unit/vagrant/host_test.rb delete mode 100644 test/unit/vagrant/hosts_test.rb diff --git a/lib/vagrant.rb b/lib/vagrant.rb index fcb102d5a..b5b33752c 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -93,7 +93,7 @@ module Vagrant autoload :Environment, 'vagrant/environment' autoload :Errors, 'vagrant/errors' autoload :Guest, 'vagrant/guest' - autoload :Hosts, 'vagrant/hosts' + autoload :Host, 'vagrant/host' autoload :Machine, 'vagrant/machine' autoload :MachineState, 'vagrant/machine_state' autoload :Plugin, 'vagrant/plugin' diff --git a/lib/vagrant/host.rb b/lib/vagrant/host.rb new file mode 100644 index 000000000..2321edd83 --- /dev/null +++ b/lib/vagrant/host.rb @@ -0,0 +1,16 @@ +require "vagrant/capability_host" + +module Vagrant + # This class handles host-OS specific interations. It is responsible for + # detecting the proper host OS implementation and delegating capabilities + # to plugins. + # + # See {Guest} for more information on capabilities. + class Host + include CapabilityHost + + def initialize(host, hosts, capabilities) + initialize_capabilities!(host, hosts, capabilities) + end + end +end diff --git a/lib/vagrant/hosts.rb b/lib/vagrant/hosts.rb deleted file mode 100644 index aa333d3d0..000000000 --- a/lib/vagrant/hosts.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'log4r' - -module Vagrant - module Hosts - # This method detects the correct host based on the `match?` methods - # implemented in the registered hosts. - # - # @param [Hash] registry Hash mapping key to host class - 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 - end -end diff --git a/lib/vagrant/plugin/v2/host.rb b/lib/vagrant/plugin/v2/host.rb index 53a526885..51e5ae3f1 100644 --- a/lib/vagrant/plugin/v2/host.rb +++ b/lib/vagrant/plugin/v2/host.rb @@ -10,19 +10,8 @@ module Vagrant # matches the host class. # # @return [Boolean] - def self.match? - nil - end - - # The precedence of the host when checking for matches. This is to - # allow certain host such as generic OS's ("Linux", "BSD", etc.) - # to be specified last. - # - # The hosts with the higher numbers will be checked first. - # - # If you're implementing a basic host, you can probably ignore this. - def self.precedence - 5 + def detect? + false end # Initializes a new host class. diff --git a/test/unit/vagrant/host_test.rb b/test/unit/vagrant/host_test.rb new file mode 100644 index 000000000..63c267e52 --- /dev/null +++ b/test/unit/vagrant/host_test.rb @@ -0,0 +1,17 @@ +require "pathname" + +require File.expand_path("../../base", __FILE__) + +describe Vagrant::Host do + include_context "capability_helpers" + + let(:capabilities) { {} } + let(:hosts) { {} } + + it "initializes the capabilities" do + described_class.any_instance.should_receive(:initialize_capabilities!). + with(:foo, hosts, capabilities) + + described_class.new(:foo, hosts, capabilities) + end +end diff --git a/test/unit/vagrant/hosts_test.rb b/test/unit/vagrant/hosts_test.rb deleted file mode 100644 index 6c7f460c6..000000000 --- a/test/unit/vagrant/hosts_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require File.expand_path("../../base", __FILE__) - -describe Vagrant::Hosts do - let(:registry) { Hash.new } - let(:base_class) { Vagrant::Plugin::V1::Host } - - it "detects the host that matches true" do - foo_klass = Class.new(base_class) do - def self.match?; false; end - end - - bar_klass = Class.new(base_class) do - def self.match?; true; end - end - - registry[:foo] = foo_klass - registry[:bar] = bar_klass - - described_class.detect(registry).should == bar_klass - end - - it "detects the host that matches true with the highest precedence first" do - foo_klass = Class.new(base_class) do - def self.match?; true; end - end - - bar_klass = Class.new(base_class) do - def self.match?; true; end - def self.precedence; 9; end - end - - registry[:foo] = foo_klass - registry[:bar] = bar_klass - - described_class.detect(registry).should == bar_klass - end -end