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