Parent

Class Index [+]

Quicksearch

Gem::Commands::UpdateCommand

Public Class Methods

new() click to toggle source
    # 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:     add_platform_option
32:     add_prerelease_option "as update targets"
33:   end

Public Instance Methods

do_rubygems_update(version) click to toggle source

Update the RubyGems software to version.

     # File lib/rubygems/commands/update_command.rb, line 137
137:   def do_rubygems_update(version)
138:     args = []
139:     args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
140:     args << '--no-rdoc' unless options[:generate_rdoc]
141:     args << '--no-ri' unless options[:generate_ri]
142:     args << '--no-format-executable' if options[:no_format_executable]
143: 
144:     update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
145: 
146:     Dir.chdir update_dir do
147:       say "Installing RubyGems #{version}"
148:       setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
149: 
150:       # Make sure old rubygems isn't loaded
151:       old = ENV["RUBYOPT"]
152:       ENV.delete("RUBYOPT")
153:       system setup_cmd
154:       ENV["RUBYOPT"] = old if old
155:     end
156:   end
execute() click to toggle source
     # File lib/rubygems/commands/update_command.rb, line 47
 47:   def execute
 48:     hig = {}
 49: 
 50:     if options[:system] then
 51:       say "Updating RubyGems"
 52: 
 53:       unless options[:args].empty? then
 54:         raise "No gem names are allowed with the --system option"
 55:       end
 56: 
 57:       rubygems_update = Gem::Specification.new
 58:       rubygems_update.name = 'rubygems-update'
 59:       rubygems_update.version = Gem::Version.new Gem::VERSION
 60:       hig['rubygems-update'] = rubygems_update
 61: 
 62:       options[:user_install] = false
 63:     else
 64:       say "Updating installed gems"
 65: 
 66:       hig = {} # highest installed gems
 67: 
 68:       Gem.source_index.each do |name, spec|
 69:         if hig[spec.name].nil? or hig[spec.name].version < spec.version then
 70:           hig[spec.name] = spec
 71:         end
 72:       end
 73:     end
 74: 
 75:     gems_to_update = which_to_update hig, options[:args]
 76: 
 77:     updated = []
 78: 
 79:     installer = Gem::DependencyInstaller.new options
 80: 
 81:     gems_to_update.uniq.sort.each do |name|
 82:       next if updated.any? { |spec| spec.name == name }
 83:       success = false
 84: 
 85:       say "Updating #{name}"
 86:       begin
 87:         installer.install name
 88:         success = true
 89:       rescue Gem::InstallError => e
 90:         alert_error "Error installing #{name}:\n\t#{e.message}"
 91:         success = false
 92:       end
 93: 
 94:       installer.installed_gems.each do |spec|
 95:         updated << spec
 96:         say "Successfully installed #{spec.full_name}" if success
 97:       end
 98:     end
 99: 
100:     if gems_to_update.include? "rubygems-update" then
101:       Gem.source_index.refresh!
102: 
103:       update_gems = Gem.source_index.find_name 'rubygems-update'
104: 
105:       latest_update_gem = update_gems.sort_by { |s| s.version }.last
106: 
107:       say "Updating RubyGems to #{latest_update_gem.version}"
108:       installed = do_rubygems_update latest_update_gem.version
109: 
110:       say "RubyGems system software updated" if installed
111:     else
112:       if updated.empty? then
113:         say "Nothing to update"
114:       else
115:         say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
116: 
117:         if options[:generate_ri] then
118:           updated.each do |gem|
119:             Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
120:           end
121: 
122:           Gem::DocManager.update_ri_cache
123:         end
124: 
125:         if options[:generate_rdoc] then
126:           updated.each do |gem|
127:             Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
128:           end
129:         end
130:       end
131:     end
132:   end
which_to_update(highest_installed_gems, gem_names) click to toggle source
     # File lib/rubygems/commands/update_command.rb, line 158
158:   def which_to_update(highest_installed_gems, gem_names)
159:     result = []
160: 
161:     highest_installed_gems.each do |l_name, l_spec|
162:       next if not gem_names.empty? and
163:               gem_names.all? { |name| /#{name}/ !~ l_spec.name }
164: 
165:       dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
166: 
167:       begin
168:         fetcher = Gem::SpecFetcher.fetcher
169:         spec_tuples = fetcher.find_matching dependency
170:       rescue Gem::RemoteFetcher::FetchError => e
171:         raise unless fetcher.warn_legacy e do
172:           require 'rubygems/source_info_cache'
173: 
174:           dependency.name = '' if dependency.name == //
175: 
176:           specs = Gem::SourceInfoCache.search_with_source dependency
177: 
178:           spec_tuples = specs.map do |spec, source_uri|
179:             [[spec.name, spec.version, spec.original_platform], source_uri]
180:           end
181:         end
182:       end
183: 
184:       matching_gems = spec_tuples.select do |(name, version, platform),|
185:         name == l_name and Gem::Platform.match platform
186:       end
187: 
188:       highest_remote_gem = matching_gems.sort_by do |(name, version),|
189:         version
190:       end.last
191: 
192:       if highest_remote_gem and
193:          l_spec.version < highest_remote_gem.first[1] then
194:         result << l_name
195:       end
196:     end
197: 
198:     result
199:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.