Geminstaller C0 Coverage Information - RCov

spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/command_manager.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/command_manager.rb 181 119
88.95%
84.03%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 #--
2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3 # All rights reserved.
4 # See LICENSE.txt for permissions.
5 #++
6 
7 require 'timeout'
8 require 'rubygems/command'
9 require 'rubygems/user_interaction'
10 
11 ##
12 # The command manager registers and installs all the individual sub-commands
13 # supported by the gem command.
14 #
15 # Extra commands can be provided by writing a rubygems_plugin.rb
16 # file in an installed gem.  You should register your command against the
17 # Gem::CommandManager instance, like this:
18 #
19 #   # file rubygems_plugin.rb
20 #   require 'rubygems/command_manager'
21 #
22 #   class Gem::Commands::EditCommand < Gem::Command
23 #     # ...
24 #   end
25 #
26 #   Gem::CommandManager.instance.register_command :edit
27 #
28 # See Gem::Command for instructions on writing gem commands.
29 
30 class Gem::CommandManager
31 
32   include Gem::UserInteraction
33 
34   ##
35   # Return the authoritative instance of the command manager.
36 
37   def self.instance
38     @command_manager ||= new
39   end
40 
41   ##
42   # Register all the subcommands supported by the gem command.
43 
44   def initialize
45     @commands = {}
46     register_command :build
47     register_command :cert
48     register_command :check
49     register_command :cleanup
50     register_command :contents
51     register_command :dependency
52     register_command :environment
53     register_command :fetch
54     register_command :generate_index
55     register_command :help
56     register_command :install
57     register_command :list
58     register_command :lock
59     register_command :mirror
60     register_command :outdated
61     register_command :owner
62     register_command :pristine
63     register_command :push
64     register_command :query
65     register_command :rdoc
66     register_command :search
67     register_command :server
68     register_command :sources
69     register_command :specification
70     register_command :stale
71     register_command :uninstall
72     register_command :unpack
73     register_command :update
74     register_command :which
75   end
76 
77   ##
78   # Register the Symbol +command+ as a gem command.
79 
80   def register_command(command)
81     @commands[command] = false
82   end
83 
84   ##
85   # Return the registered command from the command name.
86 
87   def [](command_name)
88     command_name = command_name.intern
89     return nil if @commands[command_name].nil?
90     @commands[command_name] ||= load_and_instantiate(command_name)
91   end
92 
93   ##
94   # Return a sorted list of all command names (as strings).
95 
96   def command_names
97     @commands.keys.collect {|key| key.to_s}.sort
98   end
99 
100   ##
101   # Run the config specified by +args+.
102 
103   def run(args)
104     process_args(args)
105   rescue StandardError, Timeout::Error => ex
106     alert_error "While executing gem ... (#{ex.class})\n    #{ex.to_s}"
107     ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
108       Gem.configuration.backtrace
109     terminate_interaction(1)
110   rescue Interrupt
111     alert_error "Interrupted"
112     terminate_interaction(1)
113   end
114 
115   def process_args(args)
116     args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
117     if args.size == 0
118       say Gem::Command::HELP
119       terminate_interaction(1)
120     end
121     case args[0]
122     when '-h', '--help'
123       say Gem::Command::HELP
124       terminate_interaction(0)
125     when '-v', '--version'
126       say Gem::VERSION
127       terminate_interaction(0)
128     when /^-/
129       alert_error "Invalid option: #{args[0]}.  See 'gem --help'."
130       terminate_interaction(1)
131     else
132       cmd_name = args.shift.downcase
133       cmd = find_command(cmd_name)
134       cmd.invoke(*args)
135     end
136   end
137 
138   def find_command(cmd_name)
139     possibilities = find_command_possibilities cmd_name
140     if possibilities.size > 1 then
141       raise "Ambiguous command #{cmd_name} matches [#{possibilities.join(', ')}]"
142     elsif possibilities.size < 1 then
143       raise "Unknown command #{cmd_name}"
144     end
145 
146     self[possibilities.first]
147   end
148 
149   def find_command_possibilities(cmd_name)
150     len = cmd_name.length
151 
152     command_names.select { |n| cmd_name == n[0, len] }
153   end
154 
155   private
156 
157   def load_and_instantiate(command_name)
158     command_name = command_name.to_s
159     const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase } << "Command"
160     commands = Gem::Commands
161     retried = false
162 
163     begin
164       commands.const_get const_name
165     rescue NameError
166       raise if retried
167 
168       retried = true
169       begin
170         require "rubygems/commands/#{command_name}_command"
171       rescue Exception => e
172         alert_error "Loading command: #{command_name} (#{e.class})\n    #{e}"
173         ui.errs.puts "\t#{e.backtrace.join "\n\t"}" if
174           Gem.configuration.backtrace
175       end
176       retry
177     end.new
178   end
179 
180 end
181 

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8