rubygems-update 3.5.5 → 3.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +107 -0
  3. data/Manifest.txt +84 -64
  4. data/POLICIES.md +75 -6
  5. data/bundler/CHANGELOG.md +75 -0
  6. data/bundler/lib/bundler/build_metadata.rb +2 -2
  7. data/bundler/lib/bundler/cli/binstubs.rb +1 -1
  8. data/bundler/lib/bundler/cli/gem.rb +1 -1
  9. data/bundler/lib/bundler/cli/lock.rb +5 -4
  10. data/bundler/lib/bundler/cli/plugin.rb +3 -2
  11. data/bundler/lib/bundler/cli.rb +7 -24
  12. data/bundler/lib/bundler/definition.rb +111 -56
  13. data/bundler/lib/bundler/dependency.rb +2 -1
  14. data/bundler/lib/bundler/dsl.rb +16 -1
  15. data/bundler/lib/bundler/environment_preserver.rb +5 -23
  16. data/bundler/lib/bundler/fetcher/downloader.rb +1 -1
  17. data/bundler/lib/bundler/fetcher.rb +2 -2
  18. data/bundler/lib/bundler/gem_version_promoter.rb +42 -38
  19. data/bundler/lib/bundler/injector.rb +3 -2
  20. data/bundler/lib/bundler/installer.rb +2 -2
  21. data/bundler/lib/bundler/man/bundle-add.1 +1 -1
  22. data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
  23. data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
  24. data/bundler/lib/bundler/man/bundle-check.1 +3 -1
  25. data/bundler/lib/bundler/man/bundle-check.1.ronn +3 -0
  26. data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
  27. data/bundler/lib/bundler/man/bundle-config.1 +1 -3
  28. data/bundler/lib/bundler/man/bundle-config.1.ronn +0 -3
  29. data/bundler/lib/bundler/man/bundle-console.1 +1 -1
  30. data/bundler/lib/bundler/man/bundle-doctor.1 +1 -1
  31. data/bundler/lib/bundler/man/bundle-exec.1 +1 -1
  32. data/bundler/lib/bundler/man/bundle-gem.1 +1 -1
  33. data/bundler/lib/bundler/man/bundle-help.1 +1 -1
  34. data/bundler/lib/bundler/man/bundle-info.1 +1 -1
  35. data/bundler/lib/bundler/man/bundle-init.1 +1 -1
  36. data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
  37. data/bundler/lib/bundler/man/bundle-install.1 +3 -3
  38. data/bundler/lib/bundler/man/bundle-install.1.ronn +2 -2
  39. data/bundler/lib/bundler/man/bundle-list.1 +1 -1
  40. data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
  41. data/bundler/lib/bundler/man/bundle-open.1 +1 -1
  42. data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
  43. data/bundler/lib/bundler/man/bundle-platform.1 +1 -1
  44. data/bundler/lib/bundler/man/bundle-plugin.1 +7 -4
  45. data/bundler/lib/bundler/man/bundle-plugin.1.ronn +7 -3
  46. data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
  47. data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
  48. data/bundler/lib/bundler/man/bundle-show.1 +1 -1
  49. data/bundler/lib/bundler/man/bundle-update.1 +1 -1
  50. data/bundler/lib/bundler/man/bundle-version.1 +1 -1
  51. data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
  52. data/bundler/lib/bundler/man/bundle.1 +1 -1
  53. data/bundler/lib/bundler/man/gemfile.5 +3 -3
  54. data/bundler/lib/bundler/man/gemfile.5.ronn +2 -2
  55. data/bundler/lib/bundler/mirror.rb +3 -3
  56. data/bundler/lib/bundler/plugin/api/source.rb +2 -2
  57. data/bundler/lib/bundler/plugin/installer/path.rb +18 -0
  58. data/bundler/lib/bundler/plugin/installer.rb +36 -16
  59. data/bundler/lib/bundler/plugin/source_list.rb +4 -4
  60. data/bundler/lib/bundler/resolver/candidate.rb +1 -1
  61. data/bundler/lib/bundler/resolver.rb +54 -24
  62. data/bundler/lib/bundler/rubygems_ext.rb +12 -0
  63. data/bundler/lib/bundler/runtime.rb +1 -1
  64. data/bundler/lib/bundler/self_manager.rb +1 -1
  65. data/bundler/lib/bundler/settings.rb +14 -12
  66. data/bundler/lib/bundler/setup.rb +3 -0
  67. data/bundler/lib/bundler/source/git/git_proxy.rb +1 -1
  68. data/bundler/lib/bundler/source/git.rb +1 -1
  69. data/bundler/lib/bundler/source/rubygems/remote.rb +1 -1
  70. data/bundler/lib/bundler/source/rubygems.rb +7 -20
  71. data/bundler/lib/bundler/source_list.rb +17 -4
  72. data/bundler/lib/bundler/spec_set.rb +1 -1
  73. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +4 -3
  74. data/bundler/lib/bundler/templates/newgem/rubocop.yml.tt +0 -5
  75. data/bundler/lib/bundler/uri_credentials_filter.rb +2 -2
  76. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +22 -22
  77. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +1 -0
  78. data/bundler/lib/bundler/vendored_net_http.rb +7 -3
  79. data/bundler/lib/bundler/vendored_timeout.rb +7 -3
  80. data/bundler/lib/bundler/vendored_uri.rb +18 -1
  81. data/bundler/lib/bundler/version.rb +1 -1
  82. data/bundler/lib/bundler/yaml_serializer.rb +12 -0
  83. data/bundler/lib/bundler.rb +23 -2
  84. data/lib/rubygems/command.rb +1 -1
  85. data/lib/rubygems/command_manager.rb +2 -1
  86. data/lib/rubygems/commands/build_command.rb +2 -11
  87. data/lib/rubygems/commands/help_command.rb +2 -2
  88. data/lib/rubygems/commands/rdoc_command.rb +1 -8
  89. data/lib/rubygems/commands/rebuild_command.rb +264 -0
  90. data/lib/rubygems/commands/sources_command.rb +2 -2
  91. data/lib/rubygems/commands/update_command.rb +8 -9
  92. data/lib/rubygems/config_file.rb +20 -8
  93. data/lib/rubygems/defaults.rb +4 -4
  94. data/lib/rubygems/dependency.rb +2 -2
  95. data/lib/rubygems/dependency_list.rb +1 -1
  96. data/lib/rubygems/deprecate.rb +79 -77
  97. data/lib/rubygems/ext/cargo_builder.rb +1 -1
  98. data/lib/rubygems/gemcutter_utilities/webauthn_listener.rb +1 -1
  99. data/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +3 -1
  100. data/lib/rubygems/gemcutter_utilities.rb +40 -23
  101. data/lib/rubygems/gemspec_helpers.rb +19 -0
  102. data/lib/rubygems/local_remote_options.rb +6 -6
  103. data/lib/rubygems/package.rb +13 -7
  104. data/lib/rubygems/remote_fetcher.rb +3 -3
  105. data/lib/rubygems/request.rb +5 -5
  106. data/lib/rubygems/request_set.rb +1 -1
  107. data/lib/rubygems/requirement.rb +5 -0
  108. data/lib/rubygems/resolver/api_set.rb +1 -1
  109. data/lib/rubygems/resolver/best_set.rb +1 -1
  110. data/lib/rubygems/resolver/spec_specification.rb +7 -0
  111. data/lib/rubygems/resolver.rb +5 -5
  112. data/lib/rubygems/s3_uri_signer.rb +3 -3
  113. data/lib/rubygems/safe_yaml.rb +10 -1
  114. data/lib/rubygems/security.rb +1 -1
  115. data/lib/rubygems/source/git.rb +2 -2
  116. data/lib/rubygems/source_list.rb +1 -1
  117. data/lib/rubygems/specification.rb +6 -6
  118. data/lib/rubygems/specification_policy.rb +15 -7
  119. data/lib/rubygems/uri.rb +6 -6
  120. data/lib/rubygems/util/licenses.rb +43 -0
  121. data/lib/rubygems/util.rb +1 -1
  122. data/lib/rubygems/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +57 -0
  123. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/delegates/specification_provider.rb +11 -11
  124. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/action.rb +1 -1
  125. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +1 -1
  126. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +1 -1
  127. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +1 -1
  128. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +1 -1
  129. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/log.rb +1 -1
  130. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/set_payload.rb +1 -1
  131. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/tag.rb +1 -1
  132. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/vertex.rb +1 -1
  133. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  134. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/errors.rb +1 -1
  135. data/lib/rubygems/vendor/molinillo/lib/molinillo/gem_metadata.rb +6 -0
  136. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/modules/specification_provider.rb +2 -2
  137. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/modules/ui.rb +1 -1
  138. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/resolution.rb +3 -3
  139. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/resolver.rb +1 -1
  140. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/state.rb +1 -1
  141. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo.rb +2 -2
  142. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/generic_request.rb +9 -9
  143. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/header.rb +2 -2
  144. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/request.rb +3 -3
  145. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/requests.rb +30 -30
  146. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/response.rb +2 -2
  147. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/responses.rb +6 -6
  148. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/status.rb +1 -1
  149. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http.rb +15 -15
  150. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/https.rb +1 -1
  151. data/lib/rubygems/vendor/optparse/lib/optparse/uri.rb +7 -0
  152. data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse.rb +11 -11
  153. data/lib/rubygems/{timeout → vendor/timeout}/lib/timeout.rb +1 -1
  154. data/lib/rubygems/{tsort → vendor/tsort}/lib/tsort.rb +2 -2
  155. data/lib/rubygems/vendor/uri/.document +1 -0
  156. data/lib/rubygems/vendor/uri/LICENSE.txt +22 -0
  157. data/lib/rubygems/vendor/uri/lib/uri/common.rb +853 -0
  158. data/lib/rubygems/vendor/uri/lib/uri/file.rb +100 -0
  159. data/lib/rubygems/vendor/uri/lib/uri/ftp.rb +267 -0
  160. data/lib/rubygems/vendor/uri/lib/uri/generic.rb +1588 -0
  161. data/lib/rubygems/vendor/uri/lib/uri/http.rb +125 -0
  162. data/lib/rubygems/vendor/uri/lib/uri/https.rb +23 -0
  163. data/lib/rubygems/vendor/uri/lib/uri/ldap.rb +261 -0
  164. data/lib/rubygems/vendor/uri/lib/uri/ldaps.rb +22 -0
  165. data/lib/rubygems/vendor/uri/lib/uri/mailto.rb +293 -0
  166. data/lib/rubygems/vendor/uri/lib/uri/rfc2396_parser.rb +539 -0
  167. data/lib/rubygems/vendor/uri/lib/uri/rfc3986_parser.rb +183 -0
  168. data/lib/rubygems/vendor/uri/lib/uri/version.rb +6 -0
  169. data/lib/rubygems/vendor/uri/lib/uri/ws.rb +83 -0
  170. data/lib/rubygems/vendor/uri/lib/uri/wss.rb +23 -0
  171. data/lib/rubygems/vendor/uri/lib/uri.rb +104 -0
  172. data/lib/rubygems/vendored_molinillo.rb +3 -0
  173. data/lib/rubygems/vendored_net_http.rb +5 -0
  174. data/lib/rubygems/vendored_optparse.rb +3 -0
  175. data/lib/rubygems/vendored_timeout.rb +5 -0
  176. data/lib/rubygems/vendored_tsort.rb +3 -0
  177. data/lib/rubygems/yaml_serializer.rb +12 -0
  178. data/lib/rubygems.rb +2 -2
  179. data/rubygems-update.gemspec +7 -2
  180. metadata +90 -67
  181. data/lib/rubygems/net/http.rb +0 -3
  182. data/lib/rubygems/optparse/lib/optparse/uri.rb +0 -7
  183. data/lib/rubygems/optparse.rb +0 -3
  184. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  185. data/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  186. data/lib/rubygems/resolver/molinillo.rb +0 -3
  187. data/lib/rubygems/timeout.rb +0 -3
  188. data/lib/rubygems/tsort.rb +0 -3
  189. /data/lib/rubygems/{net-http → vendor/molinillo}/.document +0 -0
  190. /data/lib/rubygems/{resolver → vendor}/molinillo/LICENSE +0 -0
  191. /data/lib/rubygems/{net-protocol → vendor/net-http}/.document +0 -0
  192. /data/lib/rubygems/{net-http → vendor/net-http}/LICENSE.txt +0 -0
  193. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/backward.rb +0 -0
  194. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/exceptions.rb +0 -0
  195. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/proxy_delta.rb +0 -0
  196. /data/lib/rubygems/{optparse → vendor/net-protocol}/.document +0 -0
  197. /data/lib/rubygems/{net-protocol → vendor/net-protocol}/LICENSE.txt +0 -0
  198. /data/lib/rubygems/{net-protocol → vendor/net-protocol}/lib/net/protocol.rb +0 -0
  199. /data/lib/rubygems/{resolv → vendor/optparse}/.document +0 -0
  200. /data/lib/rubygems/{optparse → vendor/optparse}/COPYING +0 -0
  201. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optionparser.rb +0 -0
  202. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/ac.rb +0 -0
  203. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/date.rb +0 -0
  204. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/kwargs.rb +0 -0
  205. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/shellwords.rb +0 -0
  206. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/time.rb +0 -0
  207. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/version.rb +0 -0
  208. /data/lib/rubygems/{resolver/molinillo → vendor/resolv}/.document +0 -0
  209. /data/lib/rubygems/{resolv → vendor/resolv}/LICENSE.txt +0 -0
  210. /data/lib/rubygems/{resolv → vendor/resolv}/lib/resolv.rb +0 -0
  211. /data/lib/rubygems/{timeout → vendor/timeout}/.document +0 -0
  212. /data/lib/rubygems/{timeout → vendor/timeout}/LICENSE.txt +0 -0
  213. /data/lib/rubygems/{tsort → vendor/tsort}/.document +0 -0
  214. /data/lib/rubygems/{tsort → vendor/tsort}/LICENSE.txt +0 -0
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'generic'
4
+
5
+ module Gem::URI
6
+
7
+ #
8
+ # The "file" Gem::URI is defined by RFC8089.
9
+ #
10
+ class File < Generic
11
+ # A Default port of nil for Gem::URI::File.
12
+ DEFAULT_PORT = nil
13
+
14
+ #
15
+ # An Array of the available components for Gem::URI::File.
16
+ #
17
+ COMPONENT = [
18
+ :scheme,
19
+ :host,
20
+ :path
21
+ ].freeze
22
+
23
+ #
24
+ # == Description
25
+ #
26
+ # Creates a new Gem::URI::File object from components, with syntax checking.
27
+ #
28
+ # The components accepted are +host+ and +path+.
29
+ #
30
+ # The components should be provided either as an Array, or as a Hash
31
+ # with keys formed by preceding the component names with a colon.
32
+ #
33
+ # If an Array is used, the components must be passed in the
34
+ # order <code>[host, path]</code>.
35
+ #
36
+ # A path from e.g. the File class should be escaped before
37
+ # being passed.
38
+ #
39
+ # Examples:
40
+ #
41
+ # require 'rubygems/vendor/uri/lib/uri'
42
+ #
43
+ # uri1 = Gem::URI::File.build(['host.example.com', '/path/file.zip'])
44
+ # uri1.to_s # => "file://host.example.com/path/file.zip"
45
+ #
46
+ # uri2 = Gem::URI::File.build({:host => 'host.example.com',
47
+ # :path => '/ruby/src'})
48
+ # uri2.to_s # => "file://host.example.com/ruby/src"
49
+ #
50
+ # uri3 = Gem::URI::File.build({:path => Gem::URI::escape('/path/my file.txt')})
51
+ # uri3.to_s # => "file:///path/my%20file.txt"
52
+ #
53
+ def self.build(args)
54
+ tmp = Util::make_components_hash(self, args)
55
+ super(tmp)
56
+ end
57
+
58
+ # Protected setter for the host component +v+.
59
+ #
60
+ # See also Gem::URI::Generic.host=.
61
+ #
62
+ def set_host(v)
63
+ v = "" if v.nil? || v == "localhost"
64
+ @host = v
65
+ end
66
+
67
+ # do nothing
68
+ def set_port(v)
69
+ end
70
+
71
+ # raise InvalidURIError
72
+ def check_userinfo(user)
73
+ raise Gem::URI::InvalidURIError, "can not set userinfo for file Gem::URI"
74
+ end
75
+
76
+ # raise InvalidURIError
77
+ def check_user(user)
78
+ raise Gem::URI::InvalidURIError, "can not set user for file Gem::URI"
79
+ end
80
+
81
+ # raise InvalidURIError
82
+ def check_password(user)
83
+ raise Gem::URI::InvalidURIError, "can not set password for file Gem::URI"
84
+ end
85
+
86
+ # do nothing
87
+ def set_userinfo(v)
88
+ end
89
+
90
+ # do nothing
91
+ def set_user(v)
92
+ end
93
+
94
+ # do nothing
95
+ def set_password(v)
96
+ end
97
+ end
98
+
99
+ register_scheme 'FILE', File
100
+ end
@@ -0,0 +1,267 @@
1
+ # frozen_string_literal: false
2
+ # = uri/ftp.rb
3
+ #
4
+ # Author:: Akira Yamada <akira@ruby-lang.org>
5
+ # License:: You can redistribute it and/or modify it under the same term as Ruby.
6
+ #
7
+ # See Gem::URI for general documentation
8
+ #
9
+
10
+ require_relative 'generic'
11
+
12
+ module Gem::URI
13
+
14
+ #
15
+ # FTP Gem::URI syntax is defined by RFC1738 section 3.2.
16
+ #
17
+ # This class will be redesigned because of difference of implementations;
18
+ # the structure of its path. draft-hoffman-ftp-uri-04 is a draft but it
19
+ # is a good summary about the de facto spec.
20
+ # http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
21
+ #
22
+ class FTP < Generic
23
+ # A Default port of 21 for Gem::URI::FTP.
24
+ DEFAULT_PORT = 21
25
+
26
+ #
27
+ # An Array of the available components for Gem::URI::FTP.
28
+ #
29
+ COMPONENT = [
30
+ :scheme,
31
+ :userinfo, :host, :port,
32
+ :path, :typecode
33
+ ].freeze
34
+
35
+ #
36
+ # Typecode is "a", "i", or "d".
37
+ #
38
+ # * "a" indicates a text file (the FTP command was ASCII)
39
+ # * "i" indicates a binary file (FTP command IMAGE)
40
+ # * "d" indicates the contents of a directory should be displayed
41
+ #
42
+ TYPECODE = ['a', 'i', 'd'].freeze
43
+
44
+ # Typecode prefix ";type=".
45
+ TYPECODE_PREFIX = ';type='.freeze
46
+
47
+ def self.new2(user, password, host, port, path,
48
+ typecode = nil, arg_check = true) # :nodoc:
49
+ # Do not use this method! Not tested. [Bug #7301]
50
+ # This methods remains just for compatibility,
51
+ # Keep it undocumented until the active maintainer is assigned.
52
+ typecode = nil if typecode.size == 0
53
+ if typecode && !TYPECODE.include?(typecode)
54
+ raise ArgumentError,
55
+ "bad typecode is specified: #{typecode}"
56
+ end
57
+
58
+ # do escape
59
+
60
+ self.new('ftp',
61
+ [user, password],
62
+ host, port, nil,
63
+ typecode ? path + TYPECODE_PREFIX + typecode : path,
64
+ nil, nil, nil, arg_check)
65
+ end
66
+
67
+ #
68
+ # == Description
69
+ #
70
+ # Creates a new Gem::URI::FTP object from components, with syntax checking.
71
+ #
72
+ # The components accepted are +userinfo+, +host+, +port+, +path+, and
73
+ # +typecode+.
74
+ #
75
+ # The components should be provided either as an Array, or as a Hash
76
+ # with keys formed by preceding the component names with a colon.
77
+ #
78
+ # If an Array is used, the components must be passed in the
79
+ # order <code>[userinfo, host, port, path, typecode]</code>.
80
+ #
81
+ # If the path supplied is absolute, it will be escaped in order to
82
+ # make it absolute in the Gem::URI.
83
+ #
84
+ # Examples:
85
+ #
86
+ # require 'rubygems/vendor/uri/lib/uri'
87
+ #
88
+ # uri1 = Gem::URI::FTP.build(['user:password', 'ftp.example.com', nil,
89
+ # '/path/file.zip', 'i'])
90
+ # uri1.to_s # => "ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i"
91
+ #
92
+ # uri2 = Gem::URI::FTP.build({:host => 'ftp.example.com',
93
+ # :path => 'ruby/src'})
94
+ # uri2.to_s # => "ftp://ftp.example.com/ruby/src"
95
+ #
96
+ def self.build(args)
97
+
98
+ # Fix the incoming path to be generic URL syntax
99
+ # FTP path -> URL path
100
+ # foo/bar /foo/bar
101
+ # /foo/bar /%2Ffoo/bar
102
+ #
103
+ if args.kind_of?(Array)
104
+ args[3] = '/' + args[3].sub(/^\//, '%2F')
105
+ else
106
+ args[:path] = '/' + args[:path].sub(/^\//, '%2F')
107
+ end
108
+
109
+ tmp = Util::make_components_hash(self, args)
110
+
111
+ if tmp[:typecode]
112
+ if tmp[:typecode].size == 1
113
+ tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
114
+ end
115
+ tmp[:path] << tmp[:typecode]
116
+ end
117
+
118
+ return super(tmp)
119
+ end
120
+
121
+ #
122
+ # == Description
123
+ #
124
+ # Creates a new Gem::URI::FTP object from generic URL components with no
125
+ # syntax checking.
126
+ #
127
+ # Unlike build(), this method does not escape the path component as
128
+ # required by RFC1738; instead it is treated as per RFC2396.
129
+ #
130
+ # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
131
+ # +opaque+, +query+, and +fragment+, in that order.
132
+ #
133
+ def initialize(scheme,
134
+ userinfo, host, port, registry,
135
+ path, opaque,
136
+ query,
137
+ fragment,
138
+ parser = nil,
139
+ arg_check = false)
140
+ raise InvalidURIError unless path
141
+ path = path.sub(/^\//,'')
142
+ path.sub!(/^%2F/,'/')
143
+ super(scheme, userinfo, host, port, registry, path, opaque,
144
+ query, fragment, parser, arg_check)
145
+ @typecode = nil
146
+ if tmp = @path.index(TYPECODE_PREFIX)
147
+ typecode = @path[tmp + TYPECODE_PREFIX.size..-1]
148
+ @path = @path[0..tmp - 1]
149
+
150
+ if arg_check
151
+ self.typecode = typecode
152
+ else
153
+ self.set_typecode(typecode)
154
+ end
155
+ end
156
+ end
157
+
158
+ # typecode accessor.
159
+ #
160
+ # See Gem::URI::FTP::COMPONENT.
161
+ attr_reader :typecode
162
+
163
+ # Validates typecode +v+,
164
+ # returns +true+ or +false+.
165
+ #
166
+ def check_typecode(v)
167
+ if TYPECODE.include?(v)
168
+ return true
169
+ else
170
+ raise InvalidComponentError,
171
+ "bad typecode(expected #{TYPECODE.join(', ')}): #{v}"
172
+ end
173
+ end
174
+ private :check_typecode
175
+
176
+ # Private setter for the typecode +v+.
177
+ #
178
+ # See also Gem::URI::FTP.typecode=.
179
+ #
180
+ def set_typecode(v)
181
+ @typecode = v
182
+ end
183
+ protected :set_typecode
184
+
185
+ #
186
+ # == Args
187
+ #
188
+ # +v+::
189
+ # String
190
+ #
191
+ # == Description
192
+ #
193
+ # Public setter for the typecode +v+
194
+ # (with validation).
195
+ #
196
+ # See also Gem::URI::FTP.check_typecode.
197
+ #
198
+ # == Usage
199
+ #
200
+ # require 'rubygems/vendor/uri/lib/uri'
201
+ #
202
+ # uri = Gem::URI.parse("ftp://john@ftp.example.com/my_file.img")
203
+ # #=> #<Gem::URI::FTP ftp://john@ftp.example.com/my_file.img>
204
+ # uri.typecode = "i"
205
+ # uri
206
+ # #=> #<Gem::URI::FTP ftp://john@ftp.example.com/my_file.img;type=i>
207
+ #
208
+ def typecode=(typecode)
209
+ check_typecode(typecode)
210
+ set_typecode(typecode)
211
+ typecode
212
+ end
213
+
214
+ def merge(oth) # :nodoc:
215
+ tmp = super(oth)
216
+ if self != tmp
217
+ tmp.set_typecode(oth.typecode)
218
+ end
219
+
220
+ return tmp
221
+ end
222
+
223
+ # Returns the path from an FTP Gem::URI.
224
+ #
225
+ # RFC 1738 specifically states that the path for an FTP Gem::URI does not
226
+ # include the / which separates the Gem::URI path from the Gem::URI host. Example:
227
+ #
228
+ # <code>ftp://ftp.example.com/pub/ruby</code>
229
+ #
230
+ # The above Gem::URI indicates that the client should connect to
231
+ # ftp.example.com then cd to pub/ruby from the initial login directory.
232
+ #
233
+ # If you want to cd to an absolute directory, you must include an
234
+ # escaped / (%2F) in the path. Example:
235
+ #
236
+ # <code>ftp://ftp.example.com/%2Fpub/ruby</code>
237
+ #
238
+ # This method will then return "/pub/ruby".
239
+ #
240
+ def path
241
+ return @path.sub(/^\//,'').sub(/^%2F/,'/')
242
+ end
243
+
244
+ # Private setter for the path of the Gem::URI::FTP.
245
+ def set_path(v)
246
+ super("/" + v.sub(/^\//, "%2F"))
247
+ end
248
+ protected :set_path
249
+
250
+ # Returns a String representation of the Gem::URI::FTP.
251
+ def to_s
252
+ save_path = nil
253
+ if @typecode
254
+ save_path = @path
255
+ @path = @path + TYPECODE_PREFIX + @typecode
256
+ end
257
+ str = super
258
+ if @typecode
259
+ @path = save_path
260
+ end
261
+
262
+ return str
263
+ end
264
+ end
265
+
266
+ register_scheme 'FTP', FTP
267
+ end