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: 
22:     add_install_update_options
23: 
24:     OptionParser.accept Gem::Version do |value|
25:       Gem::Version.new value
26: 
27:       value
28:     end
29: 
30:     add_option('--system [VERSION]', Gem::Version,
31:                'Update the RubyGems system software') do |value, options|
32:       value = true unless value
33: 
34:       options[:system] = value
35:     end
36: 
37:     add_local_remote_options
38:     add_platform_option
39:     add_prerelease_option "as update targets"
40:   end

Public Instance Methods

execute() click to toggle source
    # File lib/rubygems/commands/update_command.rb, line 54
54:   def execute
55:     @installer = Gem::DependencyInstaller.new options
56:     @updated   = []
57: 
58:     hig = {}
59: 
60:     if options[:system] then
61:       update_rubygems
62:       return
63:     else
64:       say "Updating installed gems"
65: 
66:       hig = {} # highest installed gems
67: 
68:       Gem::Specification.each do |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].uniq
76: 
77:     updated = update_gems gems_to_update
78: 
79:     if updated.empty? then
80:       say "Nothing to update"
81:     else
82:       say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
83: 
84:       if options[:generate_ri] then
85:         updated.each do |gem|
86:           Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
87:         end
88: 
89:         Gem::DocManager.update_ri_cache
90:       end
91: 
92:       if options[:generate_rdoc] then
93:         updated.each do |gem|
94:           Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
95:         end
96:       end
97:     end
98:   end
update_gem(name, version = Gem::Requirement.default) click to toggle source
     # File lib/rubygems/commands/update_command.rb, line 100
100:   def update_gem name, version = Gem::Requirement.default
101:     return if @updated.any? { |spec| spec.name == name }
102:     success = false
103: 
104:     say "Updating #{name}"
105:     begin
106:       @installer.install name, version
107:       success = true
108:     rescue Gem::InstallError => e
109:       alert_error "Error installing #{name}:\n\t#{e.message}"
110:       success = false
111:     end
112: 
113:     @installer.installed_gems.each do |spec|
114:       @updated << spec
115:       say "Successfully installed #{spec.full_name}" if success
116:     end
117:   end
update_gems(gems_to_update) click to toggle source
     # File lib/rubygems/commands/update_command.rb, line 119
119:   def update_gems gems_to_update
120:     gems_to_update.uniq.sort.each do |(name, version)|
121:       update_gem name, version
122:     end
123: 
124:     @updated
125:   end
update_rubygems() click to toggle source

Update RubyGems software to the latest version.

     # File lib/rubygems/commands/update_command.rb, line 130
130:   def update_rubygems
131:     unless options[:args].empty? then
132:       alert_error "Gem names are not allowed with the --system option"
133:       terminate_interaction 1
134:     end
135: 
136:     options[:user_install] = false
137: 
138:     # TODO: rename version and other variable name conflicts
139:     # TODO: get rid of all this indirection on name and other BS
140: 
141:     version = options[:system]
142:     if version == true then
143:       version     = Gem::Version.new     Gem::VERSION
144:       requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
145:     else
146:       version     = Gem::Version.new     version
147:       requirement = Gem::Requirement.new version
148:     end
149: 
150:     rubygems_update         = Gem::Specification.new
151:     rubygems_update.name    = 'rubygems-update'
152:     rubygems_update.version = version
153: 
154:     hig = {
155:       'rubygems-update' => rubygems_update
156:     }
157: 
158:     gems_to_update = which_to_update hig, options[:args], :system
159:     name, up_ver   = gems_to_update.first
160:     current_ver    = Gem::Version.new Gem::VERSION
161: 
162:     target = if options[:system] == true then
163:                up_ver
164:              else
165:                version
166:              end
167: 
168:     if current_ver == target then
169:       # if options[:system] != true and version == current_ver then
170:       say "Latest version currently installed. Aborting."
171:       terminate_interaction
172:     end
173: 
174:     update_gem name, target
175: 
176:     installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
177:     version        = installed_gems.last.version
178: 
179:     args = []
180:     args << '--prefix' << Gem.prefix if Gem.prefix
181:     args << '--no-rdoc' unless options[:generate_rdoc]
182:     args << '--no-ri' unless options[:generate_ri]
183:     args << '--no-format-executable' if options[:no_format_executable]
184: 
185:     update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
186: 
187:     Dir.chdir update_dir do
188:       say "Installing RubyGems #{version}"
189:       setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
190: 
191:       # Make sure old rubygems isn't loaded
192:       old = ENV["RUBYOPT"]
193:       ENV.delete("RUBYOPT") if old
194:       installed = system setup_cmd
195:       say "RubyGems system software updated" if installed
196:       ENV["RUBYOPT"] = old if old
197:     end
198:   end
which_to_update(highest_installed_gems, gem_names, system = false) click to toggle source
     # File lib/rubygems/commands/update_command.rb, line 200
200:   def which_to_update highest_installed_gems, gem_names, system = false
201:     result = []
202: 
203:     highest_installed_gems.each do |l_name, l_spec|
204:       next if not gem_names.empty? and
205:               gem_names.all? { |name| /#{name}/ !~ l_spec.name }
206: 
207:       dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
208: 
209:       fetcher = Gem::SpecFetcher.fetcher
210:       spec_tuples = fetcher.find_matching dependency
211: 
212:       matching_gems = spec_tuples.select do |(name, _, platform),|
213:         name == l_name and Gem::Platform.match platform
214:       end
215: 
216:       highest_remote_gem = matching_gems.sort_by do |(_, version),|
217:         version
218:       end.last
219: 
220:       highest_remote_gem ||= [[nil, Gem::Version.new(0), nil]] # "null" object
221:       highest_remote_ver = highest_remote_gem.first[1]
222: 
223:       if system or (l_spec.version < highest_remote_ver) then
224:         result << [l_spec.name, [l_spec.version, highest_remote_ver].max]
225:       end
226:     end
227: 
228:     result
229:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.