diff options
Diffstat (limited to 'lib/rubygems/commands/update_command.rb')
-rw-r--r-- | lib/rubygems/commands/update_command.rb | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index b7c65eb2a4..2d7da445cb 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -71,14 +71,14 @@ class Gem::Commands::UpdateCommand < Gem::Command hig = {} # highest installed gems - Gem.source_index.each do |name, spec| + Gem::Specification.each do |spec| if hig[spec.name].nil? or hig[spec.name].version < spec.version then hig[spec.name] = spec end end end - gems_to_update = which_to_update hig, options[:args] + gems_to_update = which_to_update hig, options[:args].uniq updated = update_gems gems_to_update @@ -123,8 +123,8 @@ class Gem::Commands::UpdateCommand < Gem::Command end def update_gems gems_to_update - gems_to_update.uniq.sort.each do |name| - update_gem name + gems_to_update.uniq.sort.each do |(name, version)| + update_gem name, version end @updated @@ -141,6 +141,9 @@ class Gem::Commands::UpdateCommand < Gem::Command options[:user_install] = false + # TODO: rename version and other variable name conflicts + # TODO: get rid of all this indirection on name and other BS + version = options[:system] if version == true then version = Gem::Version.new Gem::VERSION @@ -158,18 +161,25 @@ class Gem::Commands::UpdateCommand < Gem::Command 'rubygems-update' => rubygems_update } - gems_to_update = which_to_update hig, options[:args] + gems_to_update = which_to_update hig, options[:args], :system + name, up_ver = gems_to_update.first + current_ver = Gem::Version.new Gem::VERSION + + target = if options[:system] == true then + up_ver + else + version + end - if gems_to_update.empty? then + if current_ver == target then + # if options[:system] != true and version == current_ver then say "Latest version currently installed. Aborting." terminate_interaction end - update_gem gems_to_update.first, requirement + update_gem name, target - Gem.source_index.refresh! - - installed_gems = Gem.source_index.find_name 'rubygems-update', requirement + installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement version = installed_gems.last.version args = [] @@ -193,7 +203,7 @@ class Gem::Commands::UpdateCommand < Gem::Command end end - def which_to_update(highest_installed_gems, gem_names) + def which_to_update highest_installed_gems, gem_names, system = false result = [] highest_installed_gems.each do |l_name, l_spec| @@ -213,9 +223,11 @@ class Gem::Commands::UpdateCommand < Gem::Command version end.last - if highest_remote_gem and - l_spec.version < highest_remote_gem.first[1] then - result << l_name + highest_remote_gem ||= [[nil, Gem::Version.new(0), nil]] # "null" object + highest_remote_ver = highest_remote_gem.first[1] + + if system or (l_spec.version < highest_remote_ver) then + result << [l_spec.name, [l_spec.version, highest_remote_ver].max] end end |