* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / lib / rubygems / gem_runner.rb
blob5f91398b5b4f7e727eff80d7557b15557cd1bc53
1 #--
2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3 # All rights reserved.
4 # See LICENSE.txt for permissions.
5 #++
7 require 'rubygems/command_manager'
8 require 'rubygems/config_file'
9 require 'rubygems/doc_manager'
11 module Gem
13   ####################################################################
14   # Run an instance of the gem program.
15   #
16   class GemRunner
18     def initialize(options={})
19       @command_manager_class = options[:command_manager] || Gem::CommandManager
20       @config_file_class = options[:config_file] || Gem::ConfigFile
21       @doc_manager_class = options[:doc_manager] || Gem::DocManager
22     end
24     # Run the gem command with the following arguments.
25     def run(args)
26       start_time = Time.now
27       do_configuration(args)
28       cmd = @command_manager_class.instance
29       cmd.command_names.each do |command_name|
30         config_args = Gem.configuration[command_name]
31         config_args = case config_args
32                       when String
33                         config_args.split ' '
34                       else
35                         Array(config_args)
36                       end
37         Command.add_specific_extra_args command_name, config_args
38       end
39       cmd.run(Gem.configuration.args)
40       end_time = Time.now
41       if Gem.configuration.benchmark 
42         printf "\nExecution time: %0.2f seconds.\n", end_time-start_time
43         puts "Press Enter to finish"
44         STDIN.gets
45       end
46     end
48     private
50     def do_configuration(args)
51       Gem.configuration = @config_file_class.new(args)
52       Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
53       Gem::Command.extra_args = Gem.configuration[:gem]
54       @doc_manager_class.configured_args = Gem.configuration[:rdoc]
55     end
57   end # class
58 end # module