Geminstaller C0 Coverage Information - RCov

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

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/local_remote_options.rb 148 86
70.95%
55.81%

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 'uri'
8 require 'rubygems'
9 
10 ##
11 # Mixin methods for local and remote Gem::Command options.
12 
13 module Gem::LocalRemoteOptions
14 
15   ##
16   # Allows OptionParser to handle HTTP URIs.
17 
18   def accept_uri_http
19     OptionParser.accept URI::HTTP do |value|
20       begin
21         uri = URI.parse value
22       rescue URI::InvalidURIError
23         raise OptionParser::InvalidArgument, value
24       end
25 
26       unless ['http', 'https', 'file'].include?(uri.scheme)
27          raise OptionParser::InvalidArgument, value
28       end
29 
30       value
31     end
32   end
33 
34   ##
35   # Add local/remote options to the command line parser.
36 
37   def add_local_remote_options
38     add_option(:"Local/Remote", '-l', '--local',
39                'Restrict operations to the LOCAL domain') do |value, options|
40       options[:domain] = :local
41     end
42 
43     add_option(:"Local/Remote", '-r', '--remote',
44       'Restrict operations to the REMOTE domain') do |value, options|
45       options[:domain] = :remote
46     end
47 
48     add_option(:"Local/Remote", '-b', '--both',
49                'Allow LOCAL and REMOTE operations') do |value, options|
50       options[:domain] = :both
51     end
52 
53     add_bulk_threshold_option
54     add_clear_sources_option
55     add_source_option
56     add_proxy_option
57     add_update_sources_option
58   end
59 
60   ##
61   # Add the --bulk-threshold option
62 
63   def add_bulk_threshold_option
64     add_option(:"Local/Remote", '-B', '--bulk-threshold COUNT',
65                "Threshold for switching to bulk",
66                "synchronization (default #{Gem.configuration.bulk_threshold})") do
67       |value, options|
68       Gem.configuration.bulk_threshold = value.to_i
69     end
70   end
71 
72   ##
73   # Add the --clear-sources option
74 
75   def add_clear_sources_option
76     add_option(:"Local/Remote", '--clear-sources',
77                'Clear the gem sources') do |value, options|
78 
79       Gem.sources.clear
80       options[:sources_cleared] = true
81     end
82   end
83 
84   ##
85   # Add the --http-proxy option
86 
87   def add_proxy_option
88     accept_uri_http
89 
90     add_option(:"Local/Remote", '-p', '--[no-]http-proxy [URL]', URI::HTTP,
91                'Use HTTP proxy for remote operations') do |value, options|
92       options[:http_proxy] = (value == false) ? :no_proxy : value
93       Gem.configuration[:http_proxy] = options[:http_proxy]
94     end
95   end
96 
97   ##
98   # Add the --source option
99 
100   def add_source_option
101     accept_uri_http
102 
103     add_option(:"Local/Remote", '--source URL', URI::HTTP,
104                'Add URL as a remote source for gems') do |source, options|
105 
106       source << '/' if source !~ /\/\z/
107 
108       if options.delete :sources_cleared then
109         Gem.sources = [source]
110       else
111         Gem.sources << source unless Gem.sources.include?(source)
112       end
113     end
114   end
115 
116   ##
117   # Add the --update-sources option
118 
119   def add_update_sources_option
120     add_option(:"Local/Remote", '-u', '--[no-]update-sources',
121                'Update local source cache') do |value, options|
122       Gem.configuration.update_sources = value
123     end
124   end
125 
126   ##
127   # Is fetching of local and remote information enabled?
128 
129   def both?
130     options[:domain] == :both
131   end
132 
133   ##
134   # Is local fetching enabled?
135 
136   def local?
137     options[:domain] == :local || options[:domain] == :both
138   end
139 
140   ##
141   # Is remote fetching enabled?
142 
143   def remote?
144     options[:domain] == :remote || options[:domain] == :both
145   end
146 
147 end
148 

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