rubygems-update 3.4.20 → 3.4.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -0
  3. data/Manifest.txt +6 -0
  4. data/bundler/CHANGELOG.md +55 -3
  5. data/bundler/README.md +1 -2
  6. data/bundler/lib/bundler/build_metadata.rb +3 -3
  7. data/bundler/lib/bundler/cli/check.rb +1 -1
  8. data/bundler/lib/bundler/cli/gem.rb +4 -3
  9. data/bundler/lib/bundler/cli/install.rb +2 -2
  10. data/bundler/lib/bundler/cli/lock.rb +26 -23
  11. data/bundler/lib/bundler/cli/open.rb +5 -7
  12. data/bundler/lib/bundler/definition.rb +43 -26
  13. data/bundler/lib/bundler/endpoint_specification.rb +1 -1
  14. data/bundler/lib/bundler/env.rb +2 -2
  15. data/bundler/lib/bundler/errors.rb +15 -0
  16. data/bundler/lib/bundler/gem_helpers.rb +7 -0
  17. data/bundler/lib/bundler/gem_version_promoter.rb +2 -2
  18. data/bundler/lib/bundler/injector.rb +1 -1
  19. data/bundler/lib/bundler/installer/gem_installer.rb +5 -5
  20. data/bundler/lib/bundler/installer/parallel_installer.rb +0 -26
  21. data/bundler/lib/bundler/installer/standalone.rb +13 -6
  22. data/bundler/lib/bundler/lazy_specification.rb +4 -0
  23. data/bundler/lib/bundler/lockfile_parser.rb +29 -24
  24. data/bundler/lib/bundler/man/bundle-add.1 +1 -1
  25. data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
  26. data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
  27. data/bundler/lib/bundler/man/bundle-check.1 +1 -1
  28. data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
  29. data/bundler/lib/bundler/man/bundle-config.1 +1 -1
  30. data/bundler/lib/bundler/man/bundle-console.1 +1 -1
  31. data/bundler/lib/bundler/man/bundle-doctor.1 +1 -1
  32. data/bundler/lib/bundler/man/bundle-exec.1 +2 -2
  33. data/bundler/lib/bundler/man/bundle-exec.1.ronn +2 -3
  34. data/bundler/lib/bundler/man/bundle-gem.1 +1 -1
  35. data/bundler/lib/bundler/man/bundle-help.1 +1 -1
  36. data/bundler/lib/bundler/man/bundle-info.1 +1 -1
  37. data/bundler/lib/bundler/man/bundle-init.1 +1 -1
  38. data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
  39. data/bundler/lib/bundler/man/bundle-install.1 +1 -1
  40. data/bundler/lib/bundler/man/bundle-list.1 +1 -1
  41. data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
  42. data/bundler/lib/bundler/man/bundle-open.1 +1 -1
  43. data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
  44. data/bundler/lib/bundler/man/bundle-platform.1 +1 -1
  45. data/bundler/lib/bundler/man/bundle-plugin.1 +17 -17
  46. data/bundler/lib/bundler/man/bundle-plugin.1.ronn +5 -5
  47. data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
  48. data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
  49. data/bundler/lib/bundler/man/bundle-show.1 +1 -1
  50. data/bundler/lib/bundler/man/bundle-update.1 +1 -1
  51. data/bundler/lib/bundler/man/bundle-version.1 +1 -1
  52. data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
  53. data/bundler/lib/bundler/man/bundle.1 +1 -1
  54. data/bundler/lib/bundler/man/gemfile.5 +1 -1
  55. data/bundler/lib/bundler/plugin/index.rb +8 -0
  56. data/bundler/lib/bundler/plugin.rb +9 -2
  57. data/bundler/lib/bundler/resolver/package.rb +5 -0
  58. data/bundler/lib/bundler/resolver.rb +27 -7
  59. data/bundler/lib/bundler/ruby_version.rb +8 -1
  60. data/bundler/lib/bundler/rubygems_ext.rb +3 -4
  61. data/bundler/lib/bundler/rubygems_gem_installer.rb +23 -8
  62. data/bundler/lib/bundler/settings.rb +53 -16
  63. data/bundler/lib/bundler/shared_helpers.rb +16 -1
  64. data/bundler/lib/bundler/source/git/git_proxy.rb +21 -4
  65. data/bundler/lib/bundler/source/metadata.rb +1 -1
  66. data/bundler/lib/bundler/spec_set.rb +7 -4
  67. data/bundler/lib/bundler/stub_specification.rb +4 -2
  68. data/bundler/lib/bundler/templates/newgem/Rakefile.tt +6 -2
  69. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +1 -1
  70. data/bundler/lib/bundler/ui/shell.rb +1 -1
  71. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +1 -0
  72. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +21 -9
  73. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1 -1
  74. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +3 -2
  75. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +1 -1
  76. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +1 -1
  77. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +8 -10
  78. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +15 -4
  79. data/bundler/lib/bundler/vendor/thor/lib/thor/actions.rb +15 -15
  80. data/bundler/lib/bundler/vendor/thor/lib/thor/base.rb +140 -14
  81. data/bundler/lib/bundler/vendor/thor/lib/thor/command.rb +13 -4
  82. data/bundler/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +4 -0
  83. data/bundler/lib/bundler/vendor/thor/lib/thor/error.rb +16 -25
  84. data/bundler/lib/bundler/vendor/thor/lib/thor/group.rb +1 -1
  85. data/bundler/lib/bundler/vendor/thor/lib/thor/invocation.rb +1 -1
  86. data/bundler/lib/bundler/vendor/thor/lib/thor/nested_context.rb +2 -2
  87. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +20 -1
  88. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +33 -17
  89. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/option.rb +27 -8
  90. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/options.rb +44 -6
  91. data/bundler/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +2 -2
  92. data/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb +40 -30
  93. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +26 -150
  94. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/color.rb +4 -46
  95. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb +29 -0
  96. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/html.rb +3 -45
  97. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb +49 -0
  98. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb +134 -0
  99. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb +42 -0
  100. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb +38 -0
  101. data/bundler/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  102. data/bundler/lib/bundler/vendor/thor/lib/thor/util.rb +8 -7
  103. data/bundler/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  104. data/bundler/lib/bundler/vendor/thor/lib/thor.rb +155 -8
  105. data/bundler/lib/bundler/version.rb +1 -1
  106. data/bundler/lib/bundler/yaml_serializer.rb +12 -8
  107. data/bundler/lib/bundler.rb +0 -8
  108. data/lib/rubygems/basic_specification.rb +1 -1
  109. data/lib/rubygems/command.rb +5 -5
  110. data/lib/rubygems/command_manager.rb +1 -1
  111. data/lib/rubygems/commands/cert_command.rb +3 -3
  112. data/lib/rubygems/commands/check_command.rb +5 -1
  113. data/lib/rubygems/commands/cleanup_command.rb +1 -1
  114. data/lib/rubygems/commands/contents_command.rb +2 -2
  115. data/lib/rubygems/commands/environment_command.rb +2 -2
  116. data/lib/rubygems/commands/help_command.rb +3 -3
  117. data/lib/rubygems/commands/open_command.rb +1 -3
  118. data/lib/rubygems/commands/owner_command.rb +1 -1
  119. data/lib/rubygems/commands/setup_command.rb +10 -10
  120. data/lib/rubygems/commands/specification_command.rb +5 -1
  121. data/lib/rubygems/commands/stale_command.rb +1 -1
  122. data/lib/rubygems/commands/uninstall_command.rb +4 -4
  123. data/lib/rubygems/commands/unpack_command.rb +3 -3
  124. data/lib/rubygems/commands/update_command.rb +4 -4
  125. data/lib/rubygems/commands/yank_command.rb +1 -1
  126. data/lib/rubygems/config_file.rb +63 -16
  127. data/lib/rubygems/core_ext/kernel_gem.rb +1 -1
  128. data/lib/rubygems/core_ext/kernel_require.rb +2 -2
  129. data/lib/rubygems/defaults.rb +6 -2
  130. data/lib/rubygems/dependency_installer.rb +4 -4
  131. data/lib/rubygems/deprecate.rb +2 -1
  132. data/lib/rubygems/doctor.rb +2 -2
  133. data/lib/rubygems/errors.rb +1 -1
  134. data/lib/rubygems/exceptions.rb +1 -1
  135. data/lib/rubygems/ext/builder.rb +5 -4
  136. data/lib/rubygems/ext/cargo_builder.rb +2 -2
  137. data/lib/rubygems/ext/ext_conf_builder.rb +1 -1
  138. data/lib/rubygems/ext/rake_builder.rb +1 -1
  139. data/lib/rubygems/gem_runner.rb +5 -1
  140. data/lib/rubygems/gemcutter_utilities.rb +2 -2
  141. data/lib/rubygems/indexer.rb +1 -1
  142. data/lib/rubygems/install_update_options.rb +1 -1
  143. data/lib/rubygems/installer.rb +15 -20
  144. data/lib/rubygems/local_remote_options.rb +1 -1
  145. data/lib/rubygems/package/digest_io.rb +1 -1
  146. data/lib/rubygems/package/old.rb +1 -1
  147. data/lib/rubygems/package/tar_header.rb +2 -2
  148. data/lib/rubygems/package/tar_reader.rb +9 -2
  149. data/lib/rubygems/package/tar_writer.rb +2 -2
  150. data/lib/rubygems/package.rb +9 -9
  151. data/lib/rubygems/path_support.rb +1 -1
  152. data/lib/rubygems/platform.rb +12 -6
  153. data/lib/rubygems/query_utils.rb +4 -4
  154. data/lib/rubygems/remote_fetcher.rb +12 -4
  155. data/lib/rubygems/request.rb +1 -1
  156. data/lib/rubygems/request_set/gem_dependency_api.rb +1 -1
  157. data/lib/rubygems/request_set.rb +2 -1
  158. data/lib/rubygems/requirement.rb +1 -1
  159. data/lib/rubygems/resolver/api_set.rb +2 -1
  160. data/lib/rubygems/resolver/api_specification.rb +1 -1
  161. data/lib/rubygems/resolver.rb +3 -3
  162. data/lib/rubygems/security/signer.rb +10 -2
  163. data/lib/rubygems/security/trust_dir.rb +5 -5
  164. data/lib/rubygems/security.rb +1 -1
  165. data/lib/rubygems/security_option.rb +1 -1
  166. data/lib/rubygems/source/local.rb +2 -1
  167. data/lib/rubygems/source.rb +5 -1
  168. data/lib/rubygems/source_list.rb +1 -1
  169. data/lib/rubygems/spec_fetcher.rb +2 -2
  170. data/lib/rubygems/specification.rb +30 -23
  171. data/lib/rubygems/specification_policy.rb +11 -11
  172. data/lib/rubygems/uninstaller.rb +3 -3
  173. data/lib/rubygems/update_suggestion.rb +1 -1
  174. data/lib/rubygems/user_interaction.rb +2 -2
  175. data/lib/rubygems/util/licenses.rb +48 -0
  176. data/lib/rubygems/util.rb +5 -1
  177. data/lib/rubygems/validator.rb +1 -1
  178. data/lib/rubygems/version.rb +6 -5
  179. data/lib/rubygems/yaml_serializer.rb +93 -0
  180. data/lib/rubygems.rb +9 -9
  181. data/rubygems-update.gemspec +1 -1
  182. data/setup.rb +2 -0
  183. data/test/rubygems/bundler_test_gem.rb +6 -3
  184. data/test/rubygems/helper.rb +29 -21
  185. data/test/rubygems/package/tar_test_case.rb +2 -2
  186. data/test/rubygems/test_gem.rb +51 -26
  187. data/test/rubygems/test_gem_command.rb +3 -1
  188. data/test/rubygems/test_gem_command_manager.rb +6 -6
  189. data/test/rubygems/test_gem_commands_cert_command.rb +23 -23
  190. data/test/rubygems/test_gem_commands_cleanup_command.rb +2 -2
  191. data/test/rubygems/test_gem_commands_environment_command.rb +2 -1
  192. data/test/rubygems/test_gem_commands_exec_command.rb +5 -1
  193. data/test/rubygems/test_gem_commands_install_command.rb +5 -5
  194. data/test/rubygems/test_gem_commands_open_command.rb +5 -2
  195. data/test/rubygems/test_gem_commands_pristine_command.rb +2 -2
  196. data/test/rubygems/test_gem_commands_push_command.rb +7 -6
  197. data/test/rubygems/test_gem_commands_signin_command.rb +8 -8
  198. data/test/rubygems/test_gem_commands_uninstall_command.rb +21 -1
  199. data/test/rubygems/test_gem_commands_unpack_command.rb +2 -2
  200. data/test/rubygems/test_gem_config_file.rb +46 -12
  201. data/test/rubygems/test_gem_ext_builder.rb +1 -1
  202. data/test/rubygems/test_gem_ext_cargo_builder.rb +2 -2
  203. data/test/rubygems/test_gem_gemcutter_utilities.rb +8 -5
  204. data/test/rubygems/test_gem_install_update_options.rb +3 -3
  205. data/test/rubygems/test_gem_installer.rb +16 -16
  206. data/test/rubygems/test_gem_package.rb +35 -34
  207. data/test/rubygems/test_gem_package_old.rb +1 -1
  208. data/test/rubygems/test_gem_package_tar_header.rb +3 -3
  209. data/test/rubygems/test_gem_package_tar_reader.rb +19 -4
  210. data/test/rubygems/test_gem_package_tar_writer.rb +28 -28
  211. data/test/rubygems/test_gem_rdoc.rb +2 -2
  212. data/test/rubygems/test_gem_remote_fetcher.rb +13 -9
  213. data/test/rubygems/test_gem_request.rb +5 -5
  214. data/test/rubygems/test_gem_request_connection_pools.rb +2 -1
  215. data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +14 -7
  216. data/test/rubygems/test_gem_security.rb +2 -2
  217. data/test/rubygems/test_gem_security_policy.rb +2 -2
  218. data/test/rubygems/test_gem_security_signer.rb +2 -2
  219. data/test/rubygems/test_gem_security_trust_dir.rb +6 -6
  220. data/test/rubygems/test_gem_spec_fetcher.rb +2 -2
  221. data/test/rubygems/test_gem_specification.rb +29 -29
  222. data/test/rubygems/test_gem_stream_ui.rb +1 -1
  223. data/test/rubygems/test_gem_update_suggestion.rb +12 -6
  224. data/test/rubygems/test_gem_util.rb +2 -2
  225. data/test/rubygems/test_gem_version.rb +4 -2
  226. data/test/rubygems/utilities.rb +4 -3
  227. metadata +9 -3
@@ -128,10 +128,10 @@ command to remove old versions.
128
128
  if updated.empty?
129
129
  say "Nothing to update"
130
130
  else
131
- say "Gems updated: #{updated_names.join(' ')}"
131
+ say "Gems updated: #{updated_names.join(" ")}"
132
132
  end
133
- say "Gems already up-to-date: #{up_to_date_names.join(' ')}" unless up_to_date_names.empty?
134
- say "Gems not currently installed: #{not_installed_names.join(' ')}" unless not_installed_names.empty?
133
+ say "Gems already up-to-date: #{up_to_date_names.join(" ")}" unless up_to_date_names.empty?
134
+ say "Gems not currently installed: #{not_installed_names.join(" ")}" unless not_installed_names.empty?
135
135
  end
136
136
 
137
137
  def fetch_remote_gems(spec) # :nodoc:
@@ -231,7 +231,7 @@ command to remove old versions.
231
231
  highest_remote_tup = highest_remote_name_tuple(rubygems_update)
232
232
  target = highest_remote_tup ? highest_remote_tup.version : version
233
233
 
234
- return target, requirement
234
+ [target, requirement]
235
235
  end
236
236
 
237
237
  def update_gem(name, version = Gem::Requirement.default)
@@ -89,7 +89,7 @@ data you will need to change them immediately and yank your gem.
89
89
 
90
90
  def get_version_from_requirements(requirements)
91
91
  requirements.requirements.first[1].version
92
- rescue
92
+ rescue StandardError
93
93
  nil
94
94
  end
95
95
 
@@ -202,7 +202,7 @@ class Gem::ConfigFile
202
202
  @hash = @hash.merge environment_config
203
203
  end
204
204
 
205
- # HACK these override command-line args, which is bad
205
+ # HACK: these override command-line args, which is bad
206
206
  @backtrace = @hash[:backtrace] if @hash.key? :backtrace
207
207
  @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold
208
208
  @home = @hash[:gemhome] if @hash.key? :gemhome
@@ -241,9 +241,9 @@ class Gem::ConfigFile
241
241
  return if Gem.win_platform? # windows doesn't write 0600 as 0600
242
242
  return unless File.exist? credentials_path
243
243
 
244
- existing_permissions = File.stat(credentials_path).mode & 0777
244
+ existing_permissions = File.stat(credentials_path).mode & 0o777
245
245
 
246
- return if existing_permissions == 0600
246
+ return if existing_permissions == 0o600
247
247
 
248
248
  alert_error <<-ERROR
249
249
  Your gem push credentials file located at:
@@ -324,11 +324,9 @@ if you believe they were disclosed to a third party.
324
324
  require "fileutils"
325
325
  FileUtils.mkdir_p(dirname)
326
326
 
327
- Gem.load_yaml
328
-
329
- permissions = 0600 & (~File.umask)
327
+ permissions = 0o600 & (~File.umask)
330
328
  File.open(credentials_path, "w", permissions) do |f|
331
- f.write config.to_yaml
329
+ f.write self.class.dump_with_rubygems_yaml(config)
332
330
  end
333
331
 
334
332
  load_api_keys # reload
@@ -344,20 +342,18 @@ if you believe they were disclosed to a third party.
344
342
  end
345
343
 
346
344
  def load_file(filename)
347
- Gem.load_yaml
348
-
349
345
  yaml_errors = [ArgumentError]
350
- yaml_errors << Psych::SyntaxError if defined?(Psych::SyntaxError)
351
346
 
352
347
  return {} unless filename && !filename.empty? && File.exist?(filename)
353
348
 
354
349
  begin
355
- content = Gem::SafeYAML.load(File.read(filename))
356
- unless content.is_a? Hash
350
+ config = self.class.load_with_rubygems_config_hash(File.read(filename))
351
+ if config.keys.any? {|k| k.to_s.gsub(%r{https?:\/\/}, "").include?(": ") }
357
352
  warn "Failed to load #{filename} because it doesn't contain valid YAML hash"
358
353
  return {}
354
+ else
355
+ return config
359
356
  end
360
- return content
361
357
  rescue *yaml_errors => e
362
358
  warn "Failed to load #{filename}, #{e}"
363
359
  rescue Errno::EACCES
@@ -483,11 +479,11 @@ if you believe they were disclosed to a third party.
483
479
 
484
480
  @hash.each do |key, value|
485
481
  key = key.to_s
486
- next if key =~ re
482
+ next if key&.match?(re)
487
483
  yaml_hash[key.to_s] = value
488
484
  end
489
485
 
490
- yaml_hash.to_yaml
486
+ self.class.dump_with_rubygems_yaml(yaml_hash)
491
487
  end
492
488
 
493
489
  # Writes out this config file, replacing its source.
@@ -522,6 +518,57 @@ if you believe they were disclosed to a third party.
522
518
  attr_reader :hash
523
519
  protected :hash
524
520
 
521
+ def self.dump_with_rubygems_yaml(content)
522
+ content.transform_keys! do |k|
523
+ k.is_a?(Symbol) ? ":#{k}" : k
524
+ end
525
+
526
+ require_relative "yaml_serializer"
527
+ Gem::YAMLSerializer.dump(content)
528
+ end
529
+
530
+ def self.load_with_rubygems_config_hash(yaml)
531
+ require_relative "yaml_serializer"
532
+
533
+ content = Gem::YAMLSerializer.load(yaml)
534
+
535
+ content.transform_keys! do |k|
536
+ if k.match?(/\A:(.*)\Z/)
537
+ k[1..-1].to_sym
538
+ elsif k.include?("__") || k.match?(%r{/\Z})
539
+ if k.is_a?(Symbol)
540
+ k.to_s.gsub(/__/,".").gsub(%r{/\Z}, "").to_sym
541
+ else
542
+ k.dup.gsub(/__/,".").gsub(%r{/\Z}, "")
543
+ end
544
+ else
545
+ k
546
+ end
547
+ end
548
+
549
+ content.transform_values! do |v|
550
+ if v.is_a?(String)
551
+ if v.match?(/\A:(.*)\Z/)
552
+ v[1..-1].to_sym
553
+ elsif v.match?(/\A[+-]?\d+\Z/)
554
+ v.to_i
555
+ elsif v.match?(/\Atrue|false\Z/)
556
+ v == "true"
557
+ elsif v.empty?
558
+ nil
559
+ else
560
+ v
561
+ end
562
+ elsif v.is_a?(Hash) && v.empty?
563
+ nil
564
+ else
565
+ v
566
+ end
567
+ end
568
+
569
+ content
570
+ end
571
+
525
572
  private
526
573
 
527
574
  def set_config_file_name(args)
@@ -534,7 +581,7 @@ if you believe they were disclosed to a third party.
534
581
  need_config_file_name = false
535
582
  elsif arg =~ /^--config-file=(.*)/
536
583
  @config_file_name = $1
537
- elsif arg =~ /^--config-file$/
584
+ elsif /^--config-file$/.match?(arg)
538
585
  need_config_file_name = true
539
586
  end
540
587
  end
@@ -39,7 +39,7 @@ module Kernel
39
39
 
40
40
  if gem_name.is_a? Gem::Dependency
41
41
  unless Gem::Deprecate.skip
42
- warn "#{Gem.location_of_caller.join ':'}:Warning: Kernel.gem no longer "\
42
+ warn "#{Gem.location_of_caller.join ":"}:Warning: Kernel.gem no longer "\
43
43
  "accepts a Gem::Dependency object, please pass the name "\
44
44
  "and requirements directly"
45
45
  end
@@ -128,7 +128,7 @@ module Kernel
128
128
 
129
129
  if names.size > 1
130
130
  RUBYGEMS_ACTIVATION_MONITOR.exit
131
- raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ', '}"
131
+ raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ", "}"
132
132
  end
133
133
 
134
134
  # Ok, now find a gem that has no conflicts, starting
@@ -146,7 +146,7 @@ module Kernel
146
146
  end
147
147
 
148
148
  RUBYGEMS_ACTIVATION_MONITOR.exit
149
- return gem_original_require(path)
149
+ gem_original_require(path)
150
150
  rescue LoadError => load_error
151
151
  if load_error.path == path
152
152
  RUBYGEMS_ACTIVATION_MONITOR.enter
@@ -80,7 +80,7 @@ module Gem
80
80
 
81
81
  def self.find_home
82
82
  Dir.home.dup
83
- rescue
83
+ rescue StandardError
84
84
  if Gem.win_platform?
85
85
  File.expand_path File.join(ENV["HOMEDRIVE"] || ENV["SystemDrive"], "/")
86
86
  else
@@ -184,7 +184,11 @@ module Gem
184
184
  # Deduce Ruby's --program-prefix and --program-suffix from its install name
185
185
 
186
186
  def self.default_exec_format
187
- exec_format = RbConfig::CONFIG["ruby_install_name"].sub("ruby", "%s") rescue "%s"
187
+ exec_format = begin
188
+ RbConfig::CONFIG["ruby_install_name"].sub("ruby", "%s")
189
+ rescue StandardError
190
+ "%s"
191
+ end
188
192
 
189
193
  unless exec_format.include?("%s")
190
194
  raise Gem::Exception,
@@ -19,12 +19,12 @@ class Gem::DependencyInstaller
19
19
  DEFAULT_OPTIONS = { # :nodoc:
20
20
  :env_shebang => false,
21
21
  :document => %w[ri],
22
- :domain => :both, # HACK dup
22
+ :domain => :both, # HACK: dup
23
23
  :force => false,
24
- :format_executable => false, # HACK dup
24
+ :format_executable => false, # HACK: dup
25
25
  :ignore_dependencies => false,
26
26
  :prerelease => false,
27
- :security_policy => nil, # HACK NoSecurity requires OpenSSL. AlmostNo? Low?
27
+ :security_policy => nil, # HACK: NoSecurity requires OpenSSL. AlmostNo? Low?
28
28
  :wrappers => true,
29
29
  :build_args => nil,
30
30
  :build_docs_in_background => false,
@@ -292,7 +292,7 @@ class Gem::DependencyInstaller
292
292
  src = Gem::Source::SpecificFile.new dep_or_name
293
293
  installer_set.add_local dep_or_name, src.spec, src
294
294
  version = src.spec.version if version == Gem::Requirement.default
295
- elsif dep_or_name =~ /\.gem$/
295
+ elsif dep_or_name =~ /\.gem$/ # rubocop:disable Performance/RegexpMatch
296
296
  Dir[dep_or_name].each do |name|
297
297
  src = Gem::Source::SpecificFile.new name
298
298
  installer_set.add_local dep_or_name, src.spec, src
@@ -83,7 +83,8 @@ module Gem::Deprecate
83
83
  # Temporarily turn off warnings. Intended for tests only.
84
84
 
85
85
  def skip_during
86
- Gem::Deprecate.skip, original = true, Gem::Deprecate.skip
86
+ original = Gem::Deprecate.skip
87
+ Gem::Deprecate.skip = true
87
88
  yield
88
89
  ensure
89
90
  Gem::Deprecate.skip = original
@@ -33,7 +33,7 @@ class Gem::Doctor
33
33
  Gem::REPOSITORY_SUBDIRECTORIES.sort -
34
34
  REPOSITORY_EXTENSION_MAP.map {|(k,_)| k }.sort
35
35
 
36
- raise "Update REPOSITORY_EXTENSION_MAP, missing: #{missing.join ', '}" unless
36
+ raise "Update REPOSITORY_EXTENSION_MAP, missing: #{missing.join ", "}" unless
37
37
  missing.empty?
38
38
 
39
39
  ##
@@ -111,7 +111,7 @@ class Gem::Doctor
111
111
 
112
112
  basename = File.basename(child, extension)
113
113
  next if installed_specs.include? basename
114
- next if /^rubygems-\d/ =~ basename
114
+ next if /^rubygems-\d/.match?(basename)
115
115
  next if "specifications" == sub_directory && "default" == basename
116
116
  next if "plugins" == sub_directory && Gem.plugin_suffix_regexp =~ (basename)
117
117
 
@@ -61,7 +61,7 @@ module Gem
61
61
 
62
62
  def build_message
63
63
  names = specs.map(&:full_name)
64
- "Could not find '#{name}' (#{requirement}) - did find: [#{names.join ','}]\n"
64
+ "Could not find '#{name}' (#{requirement}) - did find: [#{names.join ","}]\n"
65
65
  end
66
66
  end
67
67
 
@@ -264,7 +264,7 @@ class Gem::UnsatisfiableDependencyError < Gem::DependencyError
264
264
  def initialize(dep, platform_mismatch=nil)
265
265
  if platform_mismatch && !platform_mismatch.empty?
266
266
  plats = platform_mismatch.map {|x| x.platform.to_s }.sort.uniq
267
- super "Unable to resolve dependency: No match for '#{dep}' on this platform. Found: #{plats.join(', ')}"
267
+ super "Unable to resolve dependency: No match for '#{dep}' on this platform. Found: #{plats.join(", ")}"
268
268
  else
269
269
  if dep.explicit?
270
270
  super "Unable to resolve dependency: user requested '#{dep}'"
@@ -77,7 +77,8 @@ class Gem::Ext::Builder
77
77
  verbose = Gem.configuration.really_verbose
78
78
 
79
79
  begin
80
- rubygems_gemdeps, ENV["RUBYGEMS_GEMDEPS"] = ENV["RUBYGEMS_GEMDEPS"], nil
80
+ rubygems_gemdeps = ENV["RUBYGEMS_GEMDEPS"]
81
+ ENV["RUBYGEMS_GEMDEPS"] = nil
81
82
  if verbose
82
83
  puts("current directory: #{dir}")
83
84
  p(command)
@@ -90,7 +91,7 @@ class Gem::Ext::Builder
90
91
  build_env = { "SOURCE_DATE_EPOCH" => Gem.source_date_epoch_string }.merge(env)
91
92
  output, status = begin
92
93
  Open3.capture2e(build_env, *command, :chdir => dir)
93
- rescue => error
94
+ rescue StandardError => error
94
95
  raise Gem::InstallError, "#{command_name || class_name} failed#{error.message}"
95
96
  end
96
97
  if verbose
@@ -190,7 +191,7 @@ EOF
190
191
  verbose { results.join("\n") }
191
192
 
192
193
  write_gem_make_out results.join "\n"
193
- rescue => e
194
+ rescue StandardError => e
194
195
  results << e.message
195
196
  build_error(results.join("\n"), $@)
196
197
  end
@@ -206,7 +207,7 @@ EOF
206
207
  if @build_args.empty?
207
208
  say "Building native extensions. This could take a while..."
208
209
  else
209
- say "Building native extensions with: '#{@build_args.join ' '}'"
210
+ say "Building native extensions with: '#{@build_args.join " "}'"
210
211
  say "This could take a while..."
211
212
  end
212
213
 
@@ -199,7 +199,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
199
199
  output, status =
200
200
  begin
201
201
  Open3.capture2e(cargo, "metadata", "--no-deps", "--format-version", "1", :chdir => cargo_dir)
202
- rescue => error
202
+ rescue StandardError => error
203
203
  raise Gem::InstallError, "cargo metadata failed #{error.message}"
204
204
  end
205
205
 
@@ -313,7 +313,7 @@ EOF
313
313
  deffile_path
314
314
  end
315
315
 
316
- # We have to basically reimplement RbConfig::CONFIG['SOEXT'] here to support
316
+ # We have to basically reimplement <code>RbConfig::CONFIG['SOEXT']</code> here to support
317
317
  # Ruby < 2.5
318
318
  #
319
319
  # @see https://github.com/ruby/ruby/blob/c87c027f18c005460746a74c07cd80ee355b16e4/configure.ac#L3185
@@ -43,7 +43,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
43
43
 
44
44
  full_tmp_dest = File.join(extension_dir, tmp_dest_relative)
45
45
 
46
- # TODO remove in RubyGems 4
46
+ # TODO: remove in RubyGems 4
47
47
  if Gem.install_extension_in_lib && lib_dir
48
48
  FileUtils.mkdir_p lib_dir
49
49
  entries = Dir.entries(full_tmp_dest) - %w[. ..]
@@ -10,7 +10,7 @@ require_relative "../shellwords"
10
10
 
11
11
  class Gem::Ext::RakeBuilder < Gem::Ext::Builder
12
12
  def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_dir=Dir.pwd)
13
- if File.basename(extension) =~ /mkrf_conf/i
13
+ if /mkrf_conf/i.match?(File.basename(extension))
14
14
  run([Gem.ruby, File.basename(extension), *args], results, class_name, extension_dir)
15
15
  end
16
16
 
@@ -33,7 +33,11 @@ class Gem::GemRunner
33
33
 
34
34
  do_configuration args
35
35
 
36
- Gem.load_env_plugins rescue nil
36
+ begin
37
+ Gem.load_env_plugins
38
+ rescue StandardError
39
+ nil
40
+ end
37
41
  Gem.load_plugins
38
42
 
39
43
  cmd = @command_manager_class.instance
@@ -216,7 +216,7 @@ module Gem::GemcutterUtilities
216
216
  say clean_text(response.body)
217
217
  end
218
218
  when Net::HTTPPermanentRedirect, Net::HTTPRedirection then
219
- message = "The request has redirected permanently to #{response['location']}. Please check your defined push host URL."
219
+ message = "The request has redirected permanently to #{response["location"]}. Please check your defined push host URL."
220
220
  message = "#{error_prefix}: #{message}" if error_prefix
221
221
 
222
222
  say clean_text(message)
@@ -338,7 +338,7 @@ module Gem::GemcutterUtilities
338
338
  end
339
339
 
340
340
  with_response response do |resp|
341
- Gem::SafeYAML.load clean_text(resp.body)
341
+ Gem::ConfigFile.load_with_rubygems_config_hash(clean_text(resp.body))
342
342
  end
343
343
  end
344
344
 
@@ -327,7 +327,7 @@ class Gem::Indexer
327
327
 
328
328
  def make_temp_directories
329
329
  FileUtils.rm_rf @directory
330
- FileUtils.mkdir_p @directory, :mode => 0700
330
+ FileUtils.mkdir_p @directory, :mode => 0o700
331
331
  FileUtils.mkdir_p @quick_marshal_dir
332
332
  end
333
333
 
@@ -142,7 +142,7 @@ module Gem::InstallUpdateOptions
142
142
  end unless v
143
143
 
144
144
  unless v
145
- message = v ? v : "(tried #{Gem::GEM_DEP_FILES.join ', '})"
145
+ message = v ? v : "(tried #{Gem::GEM_DEP_FILES.join ", "})"
146
146
 
147
147
  raise Gem::OptionParser::InvalidArgument,
148
148
  "cannot find gem dependencies file #{message}"
@@ -230,11 +230,11 @@ class Gem::Installer
230
230
  end
231
231
  end
232
232
 
233
- next unless line =~ shebang
233
+ next unless line&.match?(shebang)
234
234
 
235
235
  io.gets # blankline
236
236
 
237
- # TODO detect a specially formatted comment instead of trying
237
+ # TODO: detect a specially formatted comment instead of trying
238
238
  # to find a string inside Ruby code.
239
239
  next unless io.gets.to_s.include?("This file was generated by RubyGems")
240
240
 
@@ -316,7 +316,7 @@ class Gem::Installer
316
316
  FileUtils.rm_rf spec.extension_dir
317
317
 
318
318
  dir_mode = options[:dir_mode]
319
- FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0755
319
+ FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0o755
320
320
 
321
321
  if @options[:install_as_default]
322
322
  extract_bin
@@ -348,11 +348,6 @@ class Gem::Installer
348
348
  run_post_install_hooks
349
349
 
350
350
  spec
351
-
352
- # TODO This rescue is in the wrong place. What is raising this exception?
353
- # move this rescue to around the code that actually might raise it.
354
- rescue Zlib::GzipFile::Error
355
- raise Gem::InstallError, "gzip error installing #{gem}"
356
351
  end
357
352
 
358
353
  def run_pre_install_hooks # :nodoc:
@@ -494,7 +489,7 @@ class Gem::Installer
494
489
  next unless File.exist? bin_path
495
490
 
496
491
  mode = File.stat(bin_path).mode
497
- dir_mode = options[:prog_mode] || (mode | 0111)
492
+ dir_mode = options[:prog_mode] || (mode | 0o111)
498
493
 
499
494
  unless dir_mode == mode
500
495
  require "fileutils"
@@ -537,9 +532,9 @@ class Gem::Installer
537
532
  require "fileutils"
538
533
  FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
539
534
 
540
- File.open bin_script_path, "wb", 0755 do |file|
535
+ File.open bin_script_path, "wb", 0o755 do |file|
541
536
  file.print app_script_text(filename)
542
- file.chmod(options[:prog_mode] || 0755)
537
+ file.chmod(options[:prog_mode] || 0o755)
543
538
  end
544
539
 
545
540
  verbose bin_script_path
@@ -709,12 +704,12 @@ class Gem::Installer
709
704
  end
710
705
 
711
706
  def verify_gem_home # :nodoc:
712
- FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0755
707
+ FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0o755
713
708
  raise Gem::FilePermissionError, gem_home unless File.writable?(gem_home)
714
709
  end
715
710
 
716
711
  def verify_spec
717
- unless spec.name =~ Gem::Specification::VALID_NAME_PATTERN
712
+ unless Gem::Specification::VALID_NAME_PATTERN.match?(spec.name)
718
713
  raise Gem::InstallError, "#{spec} has an invalid name"
719
714
  end
720
715
 
@@ -726,11 +721,11 @@ class Gem::Installer
726
721
  raise Gem::InstallError, "#{spec} has an invalid extensions"
727
722
  end
728
723
 
729
- if spec.platform.to_s =~ /\R/
724
+ if /\R/.match?(spec.platform.to_s)
730
725
  raise Gem::InstallError, "#{spec.platform} is an invalid platform"
731
726
  end
732
727
 
733
- unless spec.specification_version.to_s =~ /\A\d+\z/
728
+ unless /\A\d+\z/.match?(spec.specification_version.to_s)
734
729
  raise Gem::InstallError, "#{spec} has an invalid specification_version"
735
730
  end
736
731
 
@@ -747,9 +742,9 @@ class Gem::Installer
747
742
  # Return the text for an application file.
748
743
 
749
744
  def app_script_text(bin_file_name)
750
- # note that the `load` lines cannot be indented, as old RG versions match
745
+ # NOTE: that the `load` lines cannot be indented, as old RG versions match
751
746
  # against the beginning of the line
752
- return <<-TEXT
747
+ <<-TEXT
753
748
  #{shebang bin_file_name}
754
749
  #
755
750
  # This file was generated by RubyGems.
@@ -806,7 +801,7 @@ TEXT
806
801
  rb_topdir = RbConfig::TOPDIR || File.dirname(rb_config["bindir"])
807
802
 
808
803
  # get ruby executable file name from RbConfig
809
- ruby_exe = "#{rb_config['RUBY_INSTALL_NAME']}#{rb_config['EXEEXT']}"
804
+ ruby_exe = "#{rb_config["RUBY_INSTALL_NAME"]}#{rb_config["EXEEXT"]}"
810
805
  ruby_exe = "ruby.exe" if ruby_exe.empty?
811
806
 
812
807
  if File.exist?(File.join bindir, ruby_exe)
@@ -931,7 +926,7 @@ TEXT
931
926
  build_info_dir = File.join gem_home, "build_info"
932
927
 
933
928
  dir_mode = options[:dir_mode]
934
- FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0755
929
+ FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0o755
935
930
 
936
931
  build_info_file = File.join build_info_dir, "#{spec.full_name}.info"
937
932
 
@@ -954,7 +949,7 @@ TEXT
954
949
 
955
950
  def ensure_writable_dir(dir) # :nodoc:
956
951
  begin
957
- Dir.mkdir dir, *[options[:dir_mode] && 0755].compact
952
+ Dir.mkdir dir, *[options[:dir_mode] && 0o755].compact
958
953
  rescue SystemCallError
959
954
  raise unless File.directory? dir
960
955
  end
@@ -105,7 +105,7 @@ module Gem::LocalRemoteOptions
105
105
 
106
106
  add_option(:"Local/Remote", "-s", "--source URL", URI::HTTP,
107
107
  "Append URL to list of remote gem sources") do |source, options|
108
- source << "/" if source !~ /\/\z/
108
+ source << "/" unless source.end_with?("/")
109
109
 
110
110
  if options.delete :sources_cleared
111
111
  Gem.sources = [source]
@@ -36,7 +36,7 @@ class Gem::Package::DigestIO
36
36
 
37
37
  yield digest_io
38
38
 
39
- return digests
39
+ digests
40
40
  end
41
41
 
42
42
  ##
@@ -78,7 +78,7 @@ class Gem::Package::Old < Gem::Package
78
78
 
79
79
  FileUtils.rm_rf destination
80
80
 
81
- FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0755
81
+ FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0o755
82
82
 
83
83
  File.open destination, "wb", file_mode(entry["mode"]) do |out|
84
84
  out.write file_data
@@ -125,7 +125,7 @@ class Gem::Package::TarHeader
125
125
  end
126
126
 
127
127
  def self.strict_oct(str)
128
- return str.strip.oct if str.strip =~ /\A[0-7]*\z/
128
+ return str.strip.oct if /\A[0-7]*\z/.match?(str.strip)
129
129
 
130
130
  raise ArgumentError, "#{str.inspect} is not an octal string"
131
131
  end
@@ -135,7 +135,7 @@ class Gem::Package::TarHeader
135
135
  # \ff flags a negative 256-based number
136
136
  # In case we have a match, parse it as a signed binary value
137
137
  # in big-endian order, except that the high-order bit is ignored.
138
- return str.unpack("N2").last if str =~ /\A[\x80\xff]/n
138
+ return str.unpack("N2").last if /\A[\x80\xff]/n.match?(str)
139
139
  strict_oct(str)
140
140
  end
141
141
 
@@ -50,7 +50,14 @@ class Gem::Package::TarReader
50
50
  return enum_for __method__ unless block_given?
51
51
 
52
52
  until @io.eof? do
53
- header = Gem::Package::TarHeader.from @io
53
+ begin
54
+ header = Gem::Package::TarHeader.from @io
55
+ rescue ArgumentError => e
56
+ # Specialize only exceptions from Gem::Package::TarHeader.strict_oct
57
+ raise e unless e.message.match?(/ is not an octal string$/)
58
+ raise Gem::Package::TarInvalidError, e.message
59
+ end
60
+
54
61
  return if header.empty?
55
62
  entry = Gem::Package::TarReader::Entry.new header, @io
56
63
  yield entry
@@ -83,7 +90,7 @@ class Gem::Package::TarReader
83
90
 
84
91
  return unless found
85
92
 
86
- return yield found
93
+ yield found
87
94
  ensure
88
95
  rewind
89
96
  end
@@ -190,7 +190,7 @@ class Gem::Package::TarWriter
190
190
  if signer.key
191
191
  signature = signer.sign signature_digest.digest
192
192
 
193
- add_file_simple "#{name}.sig", 0444, signature.length do |io|
193
+ add_file_simple "#{name}.sig", 0o444, signature.length do |io|
194
194
  io.write signature
195
195
  end
196
196
  end
@@ -324,6 +324,6 @@ class Gem::Package::TarWriter
324
324
  end
325
325
  end
326
326
 
327
- return name, prefix
327
+ [name, prefix]
328
328
  end
329
329
  end