| 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 18
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
Add the —bulk-threshold option
# File lib/rubygems/local_remote_options.rb, line 62
62: def add_bulk_threshold_option
63: add_option("Local/Remote""Local/Remote", '-B', '--bulk-threshold COUNT',
64: "Threshold for switching to bulk",
65: "synchronization (default #{Gem.configuration.bulk_threshold})") do
66: |value, options|
67: Gem.configuration.bulk_threshold = value.to_i
68: end
69: end
Add local/remote options to the command line parser.
# File lib/rubygems/local_remote_options.rb, line 37
37: def add_local_remote_options
38: add_option("Local/Remote""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""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""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_source_option
55: add_proxy_option
56: add_update_sources_option
57: end
Add the —http-proxy option
# File lib/rubygems/local_remote_options.rb, line 74
74: def add_proxy_option
75: accept_uri_http
76:
77: add_option("Local/Remote""Local/Remote", '-p', '--[no-]http-proxy [URL]', URI::HTTP,
78: 'Use HTTP proxy for remote operations') do |value, options|
79: options[:http_proxy] = (value == false) ? :no_proxy : value
80: Gem.configuration[:http_proxy] = options[:http_proxy]
81: end
82: end
Add the —source option
# File lib/rubygems/local_remote_options.rb, line 87
87: def add_source_option
88: accept_uri_http
89:
90: add_option("Local/Remote""Local/Remote", '--source URL', URI::HTTP,
91: 'Use URL as the remote source for gems') do |source, options|
92: source << '/' if source !~ /\/\z/
93:
94: if options[:added_source] then
95: Gem.sources << source unless Gem.sources.include?(source)
96: else
97: options[:added_source] = true
98: Gem.sources.replace [source]
99: end
100: end
101: end
Add the —update-source option
# File lib/rubygems/local_remote_options.rb, line 106
106: def add_update_sources_option
107:
108: add_option("Local/Remote""Local/Remote", '-u', '--[no-]update-sources',
109: 'Update local source cache') do |value, options|
110: Gem.configuration.update_sources = value
111: end
112: end
Is fetching of local and remote information enabled?
# File lib/rubygems/local_remote_options.rb, line 117
117: def both?
118: options[:domain] == :both
119: end