From ee33588d104408ea1c495809519eab93476d8161 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Dec 2011 00:03:28 -0800 Subject: [PATCH] Clean up system loading quite a bit --- lib/vagrant.rb | 33 +++++++++++++++++++++++++++++---- lib/vagrant/vm.rb | 18 +++--------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 183091b8c..122a5b5e8 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -43,20 +43,45 @@ module Vagrant @source_root ||= Pathname.new(File.expand_path('../../', __FILE__)) end + # Global registry of available host classes and shortcut symbols + # associated with them. + # + # This registry is used to look up the shorcuts for `config.vagrant.host`, + # or to query all hosts for automatically detecting the host system. + # The registry is global to all of Vagrant. def self.hosts @hosts ||= Registry.new end + + # Global registry of available guest classes and shortcut symbols + # associated with them. + # + # This registry is used to look up the shortcuts for `config.vm.guest`. + def self.guests + @guests ||= Registry.new + end end # # Default I18n to load the en locale I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_root) # Register the built-in hosts -Vagrant.hosts.register(:arch) { Vagrant::Hosts::Arch } +Vagrant.hosts.register(:arch) { Vagrant::Hosts::Arch } Vagrant.hosts.register(:freebsd) { Vagrant::Hosts::FreeBSD } -Vagrant.hosts.register(:fedora) { Vagrant::Hosts::Fedora } -Vagrant.hosts.register(:linux) { Vagrant::Hosts::Linux } -Vagrant.hosts.register(:bsd) { Vagrant::Hosts::BSD } +Vagrant.hosts.register(:fedora) { Vagrant::Hosts::Fedora } +Vagrant.hosts.register(:linux) { Vagrant::Hosts::Linux } +Vagrant.hosts.register(:bsd) { Vagrant::Hosts::BSD } + +# Register the built-in guests +Vagrant.guests.register(:arch) { Vagrant::Systems::Arch } +Vagrant.guests.register(:debian) { Vagrant::Systems::Debian } +Vagrant.guests.register(:freebsd) { Vagrant::Systems::FreeBSD } +Vagrant.guests.register(:gentoo) { Vagrant::Systems::Gentoo } +Vagrant.guests.register(:linux) { Vagrant::Systems::Linux } +Vagrant.guests.register(:redhat) { Vagrant::Systems::Redhat } +Vagrant.guests.register(:solaris) { Vagrant::Systems::Solaris } +Vagrant.guests.register(:suse) { Vagrant::Systems::Suse } +Vagrant.guests.register(:ubuntu) { Vagrant::Systems::Ubuntu } # Load the things which must be loaded before anything else. require 'vagrant/command' diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 2363d710b..4017b856d 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -38,21 +38,9 @@ module Vagrant raise Errors::VMSystemError, :_key => :invalid_class, :system => system.to_s if !(system <= Systems::Base) @system = system.new(self) elsif system.is_a?(Symbol) - # Hard-coded internal systems - mapping = { - :debian => Systems::Debian, - :ubuntu => Systems::Ubuntu, - :freebsd => Systems::FreeBSD, - :gentoo => Systems::Gentoo, - :redhat => Systems::Redhat, - :suse => Systems::Suse, - :linux => Systems::Linux, - :solaris => Systems::Solaris, - :arch => Systems::Arch - } - - raise Errors::VMSystemError, :_key => :unknown_type, :system => system.to_s if !mapping.has_key?(system) - @system = mapping[system].new(self) + system_klass = Vagrant.guests.get(system) + raise Errors::VMSystemError, :_key => :unknown_type, :system => system.to_s if !system_klass + @system = system_klass.new(self) else raise Errors::VMSystemError, :unspecified end