| 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: :install_dir => Gem.dir
23:
24: add_install_update_options
25:
26: add_option('--system',
27: 'Update the RubyGems system software') do |value, options|
28: options[:system] = value
29: end
30:
31: add_local_remote_options
32:
33: add_platform_option
34: end
# File lib/rubygems/commands/update_command.rb, line 109
109: def do_rubygems_update(version)
110: args = []
111: args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
112: args << '--no-rdoc' unless options[:generate_rdoc]
113: args << '--no-ri' unless options[:generate_ri]
114: args << '--no-format-executable' if options[:no_format_executable]
115:
116: update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
117:
118: success = false
119:
120: Dir.chdir update_dir do
121: say "Installing RubyGems #{version}"
122: setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
123:
124: # Make sure old rubygems isn't loaded
125: old = ENV["RUBYOPT"]
126: ENV.delete("RUBYOPT")
127: system setup_cmd
128: ENV["RUBYOPT"] = old if old
129: end
130: end
# File lib/rubygems/commands/update_command.rb, line 48
48: def execute
49: if options[:system] then
50: fail "gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get."
51: else
52: say "Updating installed gems"
53: end
54:
55: hig = {} # highest installed gems
56:
57: Gem::SourceIndex.from_installed_gems.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:
63: pattern = if options[:args].empty? then
64: //
65: else
66: Regexp.union(*options[:args])
67: end
68:
69: remote_gemspecs = Gem::SourceInfoCache.search pattern
70:
71: gems_to_update = which_to_update hig, remote_gemspecs
72:
73: updated = []
74:
75: installer = Gem::DependencyInstaller.new options
76:
77: gems_to_update.uniq.sort.each do |name|
78: next if updated.any? { |spec| spec.name == name }
79:
80: say "Updating #{name}"
81: installer.install name
82:
83: installer.installed_gems.each do |spec|
84: updated << spec
85: say "Successfully installed #{spec.full_name}"
86: end
87: end
88:
89: if gems_to_update.include? "rubygems-update" then
90: latest_ruby_gem = remote_gemspecs.select do |s|
91: s.name == 'rubygems-update'
92: end
93:
94: latest_ruby_gem = latest_ruby_gem.sort_by { |s| s.version }.last
95:
96: say "Updating version of RubyGems to #{latest_ruby_gem.version}"
97: installed = do_rubygems_update latest_ruby_gem.version
98:
99: say "RubyGems system software updated" if installed
100: else
101: if updated.empty? then
102: say "Nothing to update"
103: else
104: say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
105: end
106: end
107: end
# File lib/rubygems/commands/update_command.rb, line 132
132: def which_to_update(highest_installed_gems, remote_gemspecs)
133: result = []
134:
135: highest_installed_gems.each do |l_name, l_spec|
136: matching_gems = remote_gemspecs.select do |spec|
137: spec.name == l_name and Gem.platforms.any? do |platform|
138: platform == spec.platform
139: end
140: end
141:
142: highest_remote_gem = matching_gems.sort_by { |spec| spec.version }.last
143:
144: if highest_remote_gem and
145: l_spec.version < highest_remote_gem.version then
146: result << l_name
147: end
148: end
149:
150: result
151: end