From 2d66d94ebe33382e930efb9dac1e234796a7b1d4 Mon Sep 17 00:00:00 2001 From: Tiago Macedo Date: Fri, 25 Oct 2013 11:27:17 +0200 Subject: [PATCH] compatibility with rubygems 2.x --- plugins/commands/plugin/action/install_gem.rb | 13 +++++++++++-- plugins/commands/plugin/action/prune_gems.rb | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/commands/plugin/action/install_gem.rb b/plugins/commands/plugin/action/install_gem.rb index 868d0063e..c845b5be0 100644 --- a/plugins/commands/plugin/action/install_gem.rb +++ b/plugins/commands/plugin/action/install_gem.rb @@ -1,6 +1,10 @@ require "rubygems" require "rubygems/dependency_installer" -require "rubygems/format" +begin + require "rubygems/format" +rescue LoadError + # rubygems 2.x +end require "log4r" @@ -26,8 +30,13 @@ module VagrantPlugins if plugin_name =~ /\.gem$/ # If we're installing from a gem file, determine the name # based on the spec in the file. - pkg = Gem::Format.from_file_by_path(plugin_name) + pkg = if defined?(Gem::Format) + Gem::Format.from_file_by_path(plugin_name) + else + Gem::Package.new(plugin_name) + end find_plugin_name = pkg.spec.name + version = pkg.spec.version end # Install the gem diff --git a/plugins/commands/plugin/action/prune_gems.rb b/plugins/commands/plugin/action/prune_gems.rb index 4ec448ac1..0cccc1f05 100644 --- a/plugins/commands/plugin/action/prune_gems.rb +++ b/plugins/commands/plugin/action/prune_gems.rb @@ -126,6 +126,10 @@ module VagrantPlugins if prune_specs.length > 0 env[:gem_helper].with_environment do + + # due to a bug in rubygems 2.0, we need to load the specifications before removing any + Gem::Specification.to_a + prune_specs.each do |prune_spec| uninstaller = Gem::Uninstaller.new(prune_spec.name, { :all => true,