diff options
Diffstat (limited to 'lib/rubygems/commands/update_command.rb')
-rw-r--r-- | lib/rubygems/commands/update_command.rb | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 88d48d705e..b8de911e20 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -1,8 +1,10 @@ require 'rubygems/command' +require 'rubygems/command_manager' require 'rubygems/install_update_options' require 'rubygems/local_remote_options' require 'rubygems/source_info_cache' require 'rubygems/version_option' +require 'rubygems/commands/install_command' class Gem::Commands::UpdateCommand < Gem::Command @@ -45,7 +47,7 @@ class Gem::Commands::UpdateCommand < Gem::Command def execute if options[:system] then - say "Updating RubyGems..." + say "Updating RubyGems" unless options[:args].empty? then fail "No gem names are allowed with the --system option" @@ -53,10 +55,10 @@ class Gem::Commands::UpdateCommand < Gem::Command options[:args] = ["rubygems-update"] else - say "Updating installed gems..." + say "Updating installed gems" end - hig = highest_installed_gems = {} + hig = {} Gem::SourceIndex.from_installed_gems.each do |name, spec| if hig[spec.name].nil? or hig[spec.name].version < spec.version then @@ -64,25 +66,28 @@ class Gem::Commands::UpdateCommand < Gem::Command end end - remote_gemspecs = Gem::SourceInfoCache.search(//) + pattern = if options[:args].empty? then + // + else + Regexp.union(*options[:args]) + end - gems_to_update = if options[:args].empty? then - which_to_update(highest_installed_gems, remote_gemspecs) - else - options[:args] - end + remote_gemspecs = Gem::SourceInfoCache.search pattern - options[:domain] = :remote # install from remote source + gems_to_update = which_to_update hig, remote_gemspecs - # HACK use the real API - install_command = Gem::CommandManager.instance['install'] + updated = [] + # HACK use the real API gems_to_update.uniq.sort.each do |name| - say "Attempting remote update of #{name}" - options[:args] = [name] - options[:ignore_dependencies] = true # HACK skip seen gems instead - install_command.merge_options(options) - install_command.execute + next if updated.any? { |spec| spec.name == name } + say "Updating #{name}" + installer = Gem::DependencyInstaller.new options + installer.install name + installer.installed_gems.each do |spec| + updated << spec + say "Successfully installed #{spec.full_name}" + end end if gems_to_update.include? "rubygems-update" then @@ -97,12 +102,10 @@ class Gem::Commands::UpdateCommand < Gem::Command say "RubyGems system software updated" if installed else - updated = gems_to_update.uniq.sort.collect { |g| g.to_s } - if updated.empty? then say "Nothing to update" else - say "Gems updated: #{updated.join ', '}" + say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}" end end end |