| 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 63
63: def add_bulk_threshold_option
64: add_option("Local/Remote""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
Add the —clear-sources option
# File lib/rubygems/local_remote_options.rb, line 75
75: def add_clear_sources_option
76: add_option("Local/Remote""Local/Remote", '--clear-sources',
77: 'Clear the gem sources') do |value, options|
78:
79: Gem.sources = nil
80: options[:sources_cleared] = true
81: end
82: 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_clear_sources_option
55: add_source_option
56: add_proxy_option
57: add_update_sources_option
58: end
Add the —http-proxy option
# File lib/rubygems/local_remote_options.rb, line 87
87: def add_proxy_option
88: accept_uri_http
89:
90: add_option("Local/Remote""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
Add the —source option
# File lib/rubygems/local_remote_options.rb, line 100
100: def add_source_option
101: accept_uri_http
102:
103: add_option("Local/Remote""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
Add the —update-sources option
# File lib/rubygems/local_remote_options.rb, line 119
119: def add_update_sources_option
120: add_option(:Deprecated, '-u', '--[no-]update-sources',
121: 'Update local source cache') do |value, options|
122: Gem.configuration.update_sources = value
123: end
124: end
Is fetching of local and remote information enabled?
# File lib/rubygems/local_remote_options.rb, line 129
129: def both?
130: options[:domain] == :both
131: end