diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 2008d8785..63645f06a 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -136,6 +136,7 @@ I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_ro # Register the built-in commands Vagrant.commands.register(:box) { Vagrant::Command::Box } Vagrant.commands.register(:destroy) { Vagrant::Command::Destroy } +Vagrant.commands.register(:gem) { Vagrant::Command::Gem } Vagrant.commands.register(:halt) { Vagrant::Command::Halt } Vagrant.commands.register(:init) { Vagrant::Command::Init } Vagrant.commands.register(:package) { Vagrant::Command::Package } diff --git a/lib/vagrant/command.rb b/lib/vagrant/command.rb index 2524a1646..417450d6c 100644 --- a/lib/vagrant/command.rb +++ b/lib/vagrant/command.rb @@ -8,6 +8,7 @@ module Vagrant autoload :BoxRepackage, 'vagrant/command/box_repackage' autoload :BoxList, 'vagrant/command/box_list' autoload :Destroy, 'vagrant/command/destroy' + autoload :Gem, 'vagrant/command/gem' autoload :Halt, 'vagrant/command/halt' autoload :Init, 'vagrant/command/init' autoload :Package, 'vagrant/command/package' diff --git a/lib/vagrant/command/gem.rb b/lib/vagrant/command/gem.rb new file mode 100644 index 000000000..3eec3b2e3 --- /dev/null +++ b/lib/vagrant/command/gem.rb @@ -0,0 +1,17 @@ +require "rubygems" +require "rubygems/gem_runner" + +module Vagrant + module Command + class Gem < Base + def execute + # We just proxy the arguments onto a real RubyGems command + # but change `GEM_HOME` so that the gems are installed into + # our own private gem folder. + ENV["GEM_HOME"] = @env.gems_path.to_s + ::Gem.clear_paths + ::Gem::GemRunner.new.run(@argv.dup) + end + end + end +end diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index b92c1af5d..fc6503951 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -11,7 +11,7 @@ module Vagrant # defined as basically a folder with a "Vagrantfile." This class allows # access to the VMs, CLI, etc. all in the scope of this environment. class Environment - HOME_SUBDIRS = ["tmp", "boxes"] + HOME_SUBDIRS = ["tmp", "boxes", "gems"] DEFAULT_VM = :default DEFAULT_HOME = "~/.vagrant.d" @@ -34,6 +34,9 @@ module Vagrant # The directory where boxes are stored. attr_reader :boxes_path + # The path where the plugins are stored (gems) + attr_reader :gems_path + # The path to the default private key attr_reader :default_private_key_path @@ -80,6 +83,7 @@ module Vagrant setup_home_path @tmp_path = @home_path.join("tmp") @boxes_path = @home_path.join("boxes") + @gems_path = @home_path.join("gems") # Setup the default private key @default_private_key_path = @home_path.join("insecure_private_key")