Parent

Class Index [+]

Quicksearch

Gem::Commands::SetupCommand

Installs RubyGems itself. This command is ordinarily only available from a RubyGems checkout or tarball.

Public Class Methods

new() click to toggle source
    # File lib/rubygems/commands/setup_command.rb, line 9
 9:   def initialize
10:     require 'tmpdir'
11: 
12:     super 'setup', 'Install RubyGems',
13:           :format_executable => true, :rdoc => true, :ri => true,
14:           :site_or_vendor => :sitelibdir,
15:           :destdir => '', :prefix => ''
16: 
17:     add_option '--prefix=PREFIX',
18:                'Prefix path for installing RubyGems',
19:                'Will not affect gem repository location' do |prefix, options|
20:       options[:prefix] = File.expand_path prefix
21:     end
22: 
23:     add_option '--destdir=DESTDIR',
24:                'Root directory to install RubyGems into',
25:                'Mainly used for packaging RubyGems' do |destdir, options|
26:       options[:destdir] = File.expand_path destdir
27:     end
28: 
29:     add_option '--[no-]vendor',
30:                'Install into vendorlibdir not sitelibdir' do |vendor, options|
31:       options[:site_or_vendor] = vendor ? :vendorlibdir : :sitelibdir
32:     end
33: 
34:     add_option '--[no-]format-executable',
35:                'Makes `gem` match ruby',
36:                'If ruby is ruby18, gem will be gem18' do |value, options|
37:       options[:format_executable] = value
38:     end
39: 
40:     add_option '--[no-]rdoc',
41:                'Generate RDoc documentation for RubyGems' do |value, options|
42:       options[:rdoc] = value
43:     end
44: 
45:     add_option '--[no-]ri',
46:                'Generate RI documentation for RubyGems' do |value, options|
47:       options[:ri] = value
48:     end
49:   end

Public Instance Methods

check_ruby_version() click to toggle source
    # File lib/rubygems/commands/setup_command.rb, line 51
51:   def check_ruby_version
52:     required_version = Gem::Requirement.new '>= 1.8.7'
53: 
54:     unless required_version.satisfied_by? Gem.ruby_version then
55:       alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}"
56:       terminate_interaction 1
57:     end
58:   end
execute() click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 82
 82:   def execute
 83:     @verbose = Gem.configuration.really_verbose
 84: 
 85:     install_destdir = options[:destdir]
 86: 
 87:     unless install_destdir.empty? then
 88:       ENV['GEM_HOME'] ||= File.join(install_destdir,
 89:                                     Gem.default_dir.gsub(/^[a-zA-Z]:/, ''))
 90:     end
 91: 
 92:     check_ruby_version
 93: 
 94:     require 'fileutils'
 95:     if Gem.configuration.really_verbose then
 96:       extend FileUtils::Verbose
 97:     else
 98:       extend FileUtils
 99:     end
100: 
101:     lib_dir, bin_dir = make_destination_dirs install_destdir
102: 
103:     install_lib lib_dir
104: 
105:     install_executables bin_dir
106: 
107:     remove_old_bin_files bin_dir
108: 
109:     say "RubyGems #{Gem::VERSION} installed"
110: 
111:     uninstall_old_gemcutter
112: 
113:     install_rdoc
114: 
115:     say
116:     if @verbose then
117:       say "-" * 78
118:       say
119:     end
120: 
121:     release_notes = File.join Dir.pwd, 'History.txt'
122: 
123:     release_notes = if File.exist? release_notes then
124:                       open release_notes do |io|
125:                         text = io.gets '==='
126:                         text << io.gets('===')
127:                         text[0...3].sub(/^# coding:.*?^=/, '')
128:                       end
129:                     else
130:                       "Oh-no! Unable to find release notes!"
131:                     end
132: 
133:     say release_notes
134: 
135:     say
136:     say "-" * 78
137:     say
138: 
139:     say "RubyGems installed the following executables:"
140:     say @bin_file_names.map { |name| "\t#{name}\n" }
141:     say
142: 
143:     unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) then
144:       say "If `gem` was installed by a previous RubyGems installation, you may need"
145:       say "to remove it by hand."
146:       say
147:     end
148:   end
install_executables(bin_dir) click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 150
150:   def install_executables(bin_dir)
151:     say "Installing gem executable" if @verbose
152: 
153:     @bin_file_names = []
154: 
155:     Dir.chdir 'bin' do
156:       bin_files = Dir['*']
157: 
158:       bin_files.delete 'update_rubygems'
159: 
160:       bin_files.each do |bin_file|
161:         bin_file_formatted = if options[:format_executable] then
162:                                Gem.default_exec_format % bin_file
163:                              else
164:                                bin_file
165:                              end
166: 
167:         dest_file = File.join bin_dir, bin_file_formatted
168:         bin_tmp_file = File.join Dir.tmpdir, bin_file
169: 
170:         begin
171:           bin = File.readlines bin_file
172:           bin[0] = "#!#{Gem.ruby}\n"
173: 
174:           File.open bin_tmp_file, 'w' do |fp|
175:             fp.puts bin.join
176:           end
177: 
178:           install bin_tmp_file, dest_file, :mode => 0755
179:           @bin_file_names << dest_file
180:         ensure
181:           rm bin_tmp_file
182:         end
183: 
184:         next unless Gem.win_platform?
185: 
186:         begin
187:           bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat"
188: 
189:           File.open bin_cmd_file, 'w' do |file|
190:             file.puts @ECHO OFFIF NOT "%~f0" == "~f0" GOTO :WinNT@"#{File.basename(Gem.ruby).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9GOTO :EOF:WinNT@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %*
191:           end
192: 
193:           install bin_cmd_file, "#{dest_file}.bat", :mode => 0755
194:         ensure
195:           rm bin_cmd_file
196:         end
197:       end
198:     end
199:   end
install_lib(lib_dir) click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 208
208:   def install_lib(lib_dir)
209:     say "Installing RubyGems" if @verbose
210: 
211:     Dir.chdir 'lib' do
212:       lib_files = Dir[File.join('**', '*rb')]
213: 
214:       lib_files.each do |lib_file|
215:         dest_file = File.join lib_dir, lib_file
216:         dest_dir = File.dirname dest_file
217:         mkdir_p dest_dir unless File.directory? dest_dir
218: 
219:         install lib_file, dest_file, :mode => 0644
220:       end
221:     end
222:   end
install_rdoc() click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 224
224:   def install_rdoc
225:     gem_doc_dir = File.join Gem.dir, 'doc'
226:     rubygems_name = "rubygems-#{Gem::VERSION}"
227:     rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
228: 
229:     if File.writable? gem_doc_dir and
230:        (not File.exist? rubygems_doc_dir or
231:         File.writable? rubygems_doc_dir) then
232:       say "Removing old RubyGems RDoc and ri" if @verbose
233:       Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
234:         rm_rf dir
235:       end
236: 
237:       if options[:ri] then
238:         ri_dir = File.join rubygems_doc_dir, 'ri'
239:         say "Installing #{rubygems_name} ri into #{ri_dir}" if @verbose
240:         run_rdoc '--ri', '--op', ri_dir
241:       end
242: 
243:       if options[:rdoc] then
244:         rdoc_dir = File.join rubygems_doc_dir, 'rdoc'
245:         say "Installing #{rubygems_name} rdoc into #{rdoc_dir}" if @verbose
246:         run_rdoc '--op', rdoc_dir
247:       end
248:     elsif @verbose then
249:       say "Skipping RDoc generation, #{gem_doc_dir} not writable"
250:       say "Set the GEM_HOME environment variable if you want RDoc generated"
251:     end
252:   end
make_destination_dirs(install_destdir) click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 254
254:   def make_destination_dirs(install_destdir)
255:     lib_dir = nil
256:     bin_dir = nil
257: 
258:     prefix = options[:prefix]
259:     site_or_vendor = options[:site_or_vendor]
260: 
261:     if prefix.empty? then
262:       lib_dir = Gem::ConfigMap[site_or_vendor]
263:       bin_dir = Gem::ConfigMap[:bindir]
264:     else
265:       # Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets
266:       # confused about installation location, so switch back to
267:       # sitelibdir/vendorlibdir.
268:       if defined?(APPLE_GEM_HOME) and
269:         # just in case Apple and RubyGems don't get this patched up proper.
270:         (prefix == Gem::ConfigMap[:libdir] or
271:          # this one is important
272:          prefix == File.join(Gem::ConfigMap[:libdir], 'ruby')) then
273:          lib_dir = Gem::ConfigMap[site_or_vendor]
274:          bin_dir = Gem::ConfigMap[:bindir]
275:       else
276:         lib_dir = File.join prefix, 'lib'
277:         bin_dir = File.join prefix, 'bin'
278:       end
279:     end
280: 
281:     unless install_destdir.empty? then
282:       lib_dir = File.join install_destdir, lib_dir.gsub(/^[a-zA-Z]:/, '')
283:       bin_dir = File.join install_destdir, bin_dir.gsub(/^[a-zA-Z]:/, '')
284:     end
285: 
286:     mkdir_p lib_dir
287:     mkdir_p bin_dir
288: 
289:     return lib_dir, bin_dir
290:   end
remove_old_bin_files(bin_dir) click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 292
292:   def remove_old_bin_files(bin_dir)
293:     old_bin_files = {
294:       'gem_mirror' => 'gem mirror',
295:       'gem_server' => 'gem server',
296:       'gemlock' => 'gem lock',
297:       'gemri' => 'ri',
298:       'gemwhich' => 'gem which',
299:       'index_gem_repository.rb' => 'gem generate_index',
300:     }
301: 
302:     old_bin_files.each do |old_bin_file, new_name|
303:       old_bin_path = File.join bin_dir, old_bin_file
304:       next unless File.exist? old_bin_path
305: 
306:       deprecation_message = "`#{old_bin_file}` has been deprecated.  Use `#{new_name}` instead."
307: 
308:       File.open old_bin_path, 'w' do |fp|
309:         fp.write #!#{Gem.ruby}abort "#{deprecation_message}"
310:       end
311: 
312:       next unless Gem.win_platform?
313: 
314:       File.open "#{old_bin_path}.bat", 'w' do |fp|
315:         fp.puts %{@ECHO.#{deprecation_message}}
316:       end
317:     end
318:   end
run_rdoc(*args) click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 324
324:   def run_rdoc(*args)
325:     begin
326:       gem 'rdoc'
327:     rescue Gem::LoadError
328:     end
329: 
330:     require 'rdoc/rdoc'
331: 
332:     args << '--main' << 'README.rdoc' << '--quiet'
333:     args << '.'
334:     args << 'README.rdoc' << 'UPGRADING.rdoc'
335:     args << 'LICENSE.txt' << 'MIT.txt' << 'History.txt'
336: 
337:     r = RDoc::RDoc.new
338:     r.document args
339:   end
uninstall_old_gemcutter() click to toggle source
     # File lib/rubygems/commands/setup_command.rb, line 341
341:   def uninstall_old_gemcutter
342:     require 'rubygems/uninstaller'
343: 
344:     ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true,
345:                               :version => '< 0.4')
346:     ui.uninstall
347:   rescue Gem::InstallError
348:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.