| Module | Gem::LocalRemoteOptions |
| In: |
lib/rubygems/local_remote_options.rb
|
Mixin methods for local and remote Gem::Command options.
Allows OptionParser to handle HTTP URIs.
# File lib/rubygems/local_remote_options.rb, line 13
13: def accept_uri_http
14: OptionParser.accept URI::HTTP do |value|
15: begin
16: value = URI.parse value
17: rescue URI::InvalidURIError
18: raise OptionParser::InvalidArgument, value
19: end
20:
21: raise OptionParser::InvalidArgument, value unless value.scheme == 'http'
22:
23: value
24: end
25: end
Add the —bulk-threshold option
# File lib/rubygems/local_remote_options.rb, line 51
51: def add_bulk_threshold_option
52: add_option("Local/Remote""Local/Remote", '-B', '--bulk-threshold COUNT',
53: "Threshold for switching to bulk",
54: "synchronization (default #{Gem.configuration.bulk_threshold})") do
55: |value, options|
56: Gem.configuration.bulk_threshold = value.to_i
57: end
58: end
Add local/remote options to the command line parser.
# File lib/rubygems/local_remote_options.rb, line 28
28: def add_local_remote_options
29: add_option("Local/Remote""Local/Remote", '-l', '--local',
30: 'Restrict operations to the LOCAL domain') do |value, options|
31: options[:domain] = :local
32: end
33:
34: add_option("Local/Remote""Local/Remote", '-r', '--remote',
35: 'Restrict operations to the REMOTE domain') do |value, options|
36: options[:domain] = :remote
37: end
38:
39: add_option("Local/Remote""Local/Remote", '-b', '--both',
40: 'Allow LOCAL and REMOTE operations') do |value, options|
41: options[:domain] = :both
42: end
43:
44: add_bulk_threshold_option
45: add_source_option
46: add_proxy_option
47: add_update_sources_option
48: end
Add the —http-proxy option
# File lib/rubygems/local_remote_options.rb, line 61
61: def add_proxy_option
62: accept_uri_http
63:
64: add_option("Local/Remote""Local/Remote", '-p', '--[no-]http-proxy [URL]', URI::HTTP,
65: 'Use HTTP proxy for remote operations') do |value, options|
66: options[:http_proxy] = (value == false) ? :no_proxy : value
67: Gem.configuration[:http_proxy] = options[:http_proxy]
68: end
69: end
Add the —source option
# File lib/rubygems/local_remote_options.rb, line 72
72: def add_source_option
73: accept_uri_http
74:
75: add_option("Local/Remote""Local/Remote", '--source URL', URI::HTTP,
76: 'Use URL as the remote source for gems') do |value, options|
77: if options[:added_source] then
78: Gem.sources << value
79: else
80: options[:added_source] = true
81: Gem.sources.replace [value]
82: end
83: end
84: end
Add the —source option
# File lib/rubygems/local_remote_options.rb, line 87
87: def add_update_sources_option
88:
89: add_option("Local/Remote""Local/Remote", '-u', '--[no-]update-sources',
90: 'Update local source cache') do |value, options|
91: Gem.configuration.update_sources = value
92: end
93: end