| Class | Gem::Commands::UpdateCommand |
| In: |
lib/rubygems/commands/update_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/update_command.rb, line 15
15: def initialize
16: super 'update',
17: 'Update the named gems (or all installed gems) in the local repository',
18: :generate_rdoc => true,
19: :generate_ri => true,
20: :force => false,
21: :test => false
22:
23: add_install_update_options
24:
25: add_option('--system',
26: 'Update the RubyGems system software') do |value, options|
27: options[:system] = value
28: end
29:
30: add_local_remote_options
31:
32: add_platform_option
33: end
Update the RubyGems software to version.
# File lib/rubygems/commands/update_command.rb, line 105
105: def do_rubygems_update(version)
106: args = []
107: args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
108: args << '--no-rdoc' unless options[:generate_rdoc]
109: args << '--no-ri' unless options[:generate_ri]
110: args << '--no-format-executable' if options[:no_format_executable]
111:
112: update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
113:
114: Dir.chdir update_dir do
115: say "Installing RubyGems #{version}"
116: setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
117:
118: # Make sure old rubygems isn't loaded
119: old = ENV["RUBYOPT"]
120: ENV.delete("RUBYOPT")
121: system setup_cmd
122: ENV["RUBYOPT"] = old if old
123: end
124: end
# File lib/rubygems/commands/update_command.rb, line 47
47: def execute
48: hig = {}
49:
50: if options[:system] then
51: fail "gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get."
52: else
53: say "Updating installed gems"
54:
55: hig = {} # highest installed gems
56:
57: Gem.source_index.each do |name, spec|
58: if hig[spec.name].nil? or hig[spec.name].version < spec.version then
59: hig[spec.name] = spec
60: end
61: end
62: end
63:
64: gems_to_update = which_to_update hig, options[:args]
65:
66: updated = []
67:
68: installer = Gem::DependencyInstaller.new options
69:
70: gems_to_update.uniq.sort.each do |name|
71: next if updated.any? { |spec| spec.name == name }
72:
73: say "Updating #{name}"
74: installer.install name
75:
76: installer.installed_gems.each do |spec|
77: updated << spec
78: say "Successfully installed #{spec.full_name}"
79: end
80: end
81:
82: if gems_to_update.include? "rubygems-update" then
83: Gem.source_index.refresh!
84:
85: update_gems = Gem.source_index.search 'rubygems-update'
86:
87: latest_update_gem = update_gems.sort_by { |s| s.version }.last
88:
89: say "Updating RubyGems to #{latest_update_gem.version}"
90: installed = do_rubygems_update latest_update_gem.version
91:
92: say "RubyGems system software updated" if installed
93: else
94: if updated.empty? then
95: say "Nothing to update"
96: else
97: say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
98: end
99: end
100: end
# File lib/rubygems/commands/update_command.rb, line 126
126: def which_to_update(highest_installed_gems, gem_names)
127: result = []
128:
129: highest_installed_gems.each do |l_name, l_spec|
130: next if not gem_names.empty? and
131: gem_names.all? { |name| /#{name}/ !~ l_spec.name }
132:
133: dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
134:
135: begin
136: fetcher = Gem::SpecFetcher.fetcher
137: spec_tuples = fetcher.find_matching dependency
138: rescue Gem::RemoteFetcher::FetchError => e
139: raise unless fetcher.warn_legacy e do
140: require 'rubygems/source_info_cache'
141:
142: dependency.name = '' if dependency.name == //
143:
144: specs = Gem::SourceInfoCache.search_with_source dependency
145:
146: spec_tuples = specs.map do |spec, source_uri|
147: [[spec.name, spec.version, spec.original_platform], source_uri]
148: end
149: end
150: end
151:
152: matching_gems = spec_tuples.select do |(name, version, platform),|
153: name == l_name and Gem::Platform.match platform
154: end
155:
156: highest_remote_gem = matching_gems.sort_by do |(name, version),|
157: version
158: end.last
159:
160: if highest_remote_gem and
161: l_spec.version < highest_remote_gem.first[1] then
162: result << l_name
163: end
164: end
165:
166: result
167: end