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
@@ -1,4 +1,5 @@
1
1
  require_relative "basic"
2
+ require_relative "lcs_diff"
2
3
 
3
4
  class Bundler::Thor
4
5
  module Shell
@@ -6,6 +7,8 @@ class Bundler::Thor
6
7
  # Bundler::Thor::Shell::Basic to see all available methods.
7
8
  #
8
9
  class Color < Basic
10
+ include LCSDiff
11
+
9
12
  # Embed in a String to clear all previous ANSI sequences.
10
13
  CLEAR = "\e[0m"
11
14
  # The start of an ANSI bold sequence.
@@ -105,52 +108,7 @@ class Bundler::Thor
105
108
  end
106
109
 
107
110
  def are_colors_disabled?
108
- !ENV['NO_COLOR'].nil?
109
- end
110
-
111
- # Overwrite show_diff to show diff with colors if Diff::LCS is
112
- # available.
113
- #
114
- def show_diff(destination, content) #:nodoc:
115
- if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil?
116
- actual = File.binread(destination).to_s.split("\n")
117
- content = content.to_s.split("\n")
118
-
119
- Diff::LCS.sdiff(actual, content).each do |diff|
120
- output_diff_line(diff)
121
- end
122
- else
123
- super
124
- end
125
- end
126
-
127
- def output_diff_line(diff) #:nodoc:
128
- case diff.action
129
- when "-"
130
- say "- #{diff.old_element.chomp}", :red, true
131
- when "+"
132
- say "+ #{diff.new_element.chomp}", :green, true
133
- when "!"
134
- say "- #{diff.old_element.chomp}", :red, true
135
- say "+ #{diff.new_element.chomp}", :green, true
136
- else
137
- say " #{diff.old_element.chomp}", nil, true
138
- end
139
- end
140
-
141
- # Check if Diff::LCS is loaded. If it is, use it to create pretty output
142
- # for diff.
143
- #
144
- def diff_lcs_loaded? #:nodoc:
145
- return true if defined?(Diff::LCS)
146
- return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
147
-
148
- @diff_lcs_loaded = begin
149
- require "diff/lcs"
150
- true
151
- rescue LoadError
152
- false
153
- end
111
+ !ENV["NO_COLOR"].nil? && !ENV["NO_COLOR"].empty?
154
112
  end
155
113
  end
156
114
  end
@@ -0,0 +1,29 @@
1
+ require_relative "terminal"
2
+
3
+ class Bundler::Thor
4
+ module Shell
5
+ class ColumnPrinter
6
+ attr_reader :stdout, :options
7
+
8
+ def initialize(stdout, options = {})
9
+ @stdout = stdout
10
+ @options = options
11
+ @indent = options[:indent].to_i
12
+ end
13
+
14
+ def print(array)
15
+ return if array.empty?
16
+ colwidth = (array.map { |el| el.to_s.size }.max || 0) + 2
17
+ array.each_with_index do |value, index|
18
+ # Don't output trailing spaces when printing the last column
19
+ if ((((index + 1) % (Terminal.terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length
20
+ stdout.puts value
21
+ else
22
+ stdout.printf("%-#{colwidth}s", value)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -1,4 +1,5 @@
1
1
  require_relative "basic"
2
+ require_relative "lcs_diff"
2
3
 
3
4
  class Bundler::Thor
4
5
  module Shell
@@ -6,6 +7,8 @@ class Bundler::Thor
6
7
  # Bundler::Thor::Shell::Basic to see all available methods.
7
8
  #
8
9
  class HTML < Basic
10
+ include LCSDiff
11
+
9
12
  # The start of an HTML bold sequence.
10
13
  BOLD = "font-weight: bold"
11
14
 
@@ -76,51 +79,6 @@ class Bundler::Thor
76
79
  def can_display_colors?
77
80
  true
78
81
  end
79
-
80
- # Overwrite show_diff to show diff with colors if Diff::LCS is
81
- # available.
82
- #
83
- def show_diff(destination, content) #:nodoc:
84
- if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil?
85
- actual = File.binread(destination).to_s.split("\n")
86
- content = content.to_s.split("\n")
87
-
88
- Diff::LCS.sdiff(actual, content).each do |diff|
89
- output_diff_line(diff)
90
- end
91
- else
92
- super
93
- end
94
- end
95
-
96
- def output_diff_line(diff) #:nodoc:
97
- case diff.action
98
- when "-"
99
- say "- #{diff.old_element.chomp}", :red, true
100
- when "+"
101
- say "+ #{diff.new_element.chomp}", :green, true
102
- when "!"
103
- say "- #{diff.old_element.chomp}", :red, true
104
- say "+ #{diff.new_element.chomp}", :green, true
105
- else
106
- say " #{diff.old_element.chomp}", nil, true
107
- end
108
- end
109
-
110
- # Check if Diff::LCS is loaded. If it is, use it to create pretty output
111
- # for diff.
112
- #
113
- def diff_lcs_loaded? #:nodoc:
114
- return true if defined?(Diff::LCS)
115
- return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
116
-
117
- @diff_lcs_loaded = begin
118
- require "diff/lcs"
119
- true
120
- rescue LoadError
121
- false
122
- end
123
- end
124
82
  end
125
83
  end
126
84
  end
@@ -0,0 +1,49 @@
1
+ module LCSDiff
2
+ protected
3
+
4
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
5
+ # available.
6
+ def show_diff(destination, content) #:nodoc:
7
+ if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil?
8
+ actual = File.binread(destination).to_s.split("\n")
9
+ content = content.to_s.split("\n")
10
+
11
+ Diff::LCS.sdiff(actual, content).each do |diff|
12
+ output_diff_line(diff)
13
+ end
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def output_diff_line(diff) #:nodoc:
22
+ case diff.action
23
+ when "-"
24
+ say "- #{diff.old_element.chomp}", :red, true
25
+ when "+"
26
+ say "+ #{diff.new_element.chomp}", :green, true
27
+ when "!"
28
+ say "- #{diff.old_element.chomp}", :red, true
29
+ say "+ #{diff.new_element.chomp}", :green, true
30
+ else
31
+ say " #{diff.old_element.chomp}", nil, true
32
+ end
33
+ end
34
+
35
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
36
+ # for diff.
37
+ def diff_lcs_loaded? #:nodoc:
38
+ return true if defined?(Diff::LCS)
39
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
40
+
41
+ @diff_lcs_loaded = begin
42
+ require "diff/lcs"
43
+ true
44
+ rescue LoadError
45
+ false
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,134 @@
1
+ require_relative "column_printer"
2
+ require_relative "terminal"
3
+
4
+ class Bundler::Thor
5
+ module Shell
6
+ class TablePrinter < ColumnPrinter
7
+ BORDER_SEPARATOR = :separator
8
+
9
+ def initialize(stdout, options = {})
10
+ super
11
+ @formats = []
12
+ @maximas = []
13
+ @colwidth = options[:colwidth]
14
+ @truncate = options[:truncate] == true ? Terminal.terminal_width : options[:truncate]
15
+ @padding = 1
16
+ end
17
+
18
+ def print(array)
19
+ return if array.empty?
20
+
21
+ prepare(array)
22
+
23
+ print_border_separator if options[:borders]
24
+
25
+ array.each do |row|
26
+ if options[:borders] && row == BORDER_SEPARATOR
27
+ print_border_separator
28
+ next
29
+ end
30
+
31
+ sentence = "".dup
32
+
33
+ row.each_with_index do |column, index|
34
+ sentence << format_cell(column, row.size, index)
35
+ end
36
+
37
+ sentence = truncate(sentence)
38
+ sentence << "|" if options[:borders]
39
+ stdout.puts indentation + sentence
40
+
41
+ end
42
+ print_border_separator if options[:borders]
43
+ end
44
+
45
+ private
46
+
47
+ def prepare(array)
48
+ array = array.reject{|row| row == BORDER_SEPARATOR }
49
+
50
+ @formats << "%-#{@colwidth + 2}s".dup if @colwidth
51
+ start = @colwidth ? 1 : 0
52
+
53
+ colcount = array.max { |a, b| a.size <=> b.size }.size
54
+
55
+ start.upto(colcount - 1) do |index|
56
+ maxima = array.map { |row| row[index] ? row[index].to_s.size : 0 }.max
57
+
58
+ @maximas << maxima
59
+ @formats << if options[:borders]
60
+ "%-#{maxima}s".dup
61
+ elsif index == colcount - 1
62
+ # Don't output 2 trailing spaces when printing the last column
63
+ "%-s".dup
64
+ else
65
+ "%-#{maxima + 2}s".dup
66
+ end
67
+ end
68
+
69
+ @formats << "%s"
70
+ end
71
+
72
+ def format_cell(column, row_size, index)
73
+ maxima = @maximas[index]
74
+
75
+ f = if column.is_a?(Numeric)
76
+ if options[:borders]
77
+ # With borders we handle padding separately
78
+ "%#{maxima}s"
79
+ elsif index == row_size - 1
80
+ # Don't output 2 trailing spaces when printing the last column
81
+ "%#{maxima}s"
82
+ else
83
+ "%#{maxima}s "
84
+ end
85
+ else
86
+ @formats[index]
87
+ end
88
+
89
+ cell = "".dup
90
+ cell << "|" + " " * @padding if options[:borders]
91
+ cell << f % column.to_s
92
+ cell << " " * @padding if options[:borders]
93
+ cell
94
+ end
95
+
96
+ def print_border_separator
97
+ separator = @maximas.map do |maxima|
98
+ "+" + "-" * (maxima + 2 * @padding)
99
+ end
100
+ stdout.puts indentation + separator.join + "+"
101
+ end
102
+
103
+ def truncate(string)
104
+ return string unless @truncate
105
+ as_unicode do
106
+ chars = string.chars.to_a
107
+ if chars.length <= @truncate
108
+ chars.join
109
+ else
110
+ chars[0, @truncate - 3 - @indent].join + "..."
111
+ end
112
+ end
113
+ end
114
+
115
+ def indentation
116
+ " " * @indent
117
+ end
118
+
119
+ if "".respond_to?(:encode)
120
+ def as_unicode
121
+ yield
122
+ end
123
+ else
124
+ def as_unicode
125
+ old = $KCODE # rubocop:disable Style/GlobalVars
126
+ $KCODE = "U" # rubocop:disable Style/GlobalVars
127
+ yield
128
+ ensure
129
+ $KCODE = old # rubocop:disable Style/GlobalVars
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,42 @@
1
+ class Bundler::Thor
2
+ module Shell
3
+ module Terminal
4
+ DEFAULT_TERMINAL_WIDTH = 80
5
+
6
+ class << self
7
+ # This code was copied from Rake, available under MIT-LICENSE
8
+ # Copyright (c) 2003, 2004 Jim Weirich
9
+ def terminal_width
10
+ result = if ENV["THOR_COLUMNS"]
11
+ ENV["THOR_COLUMNS"].to_i
12
+ else
13
+ unix? ? dynamic_width : DEFAULT_TERMINAL_WIDTH
14
+ end
15
+ result < 10 ? DEFAULT_TERMINAL_WIDTH : result
16
+ rescue
17
+ DEFAULT_TERMINAL_WIDTH
18
+ end
19
+
20
+ def unix?
21
+ RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris)/i
22
+ end
23
+
24
+ private
25
+
26
+ # Calculate the dynamic width of the terminal
27
+ def dynamic_width
28
+ @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
29
+ end
30
+
31
+ def dynamic_width_stty
32
+ `stty size 2>/dev/null`.split[1].to_i
33
+ end
34
+
35
+ def dynamic_width_tput
36
+ `tput cols 2>/dev/null`.to_i
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ require_relative "column_printer"
2
+ require_relative "terminal"
3
+
4
+ class Bundler::Thor
5
+ module Shell
6
+ class WrappedPrinter < ColumnPrinter
7
+ def print(message)
8
+ width = Terminal.terminal_width - @indent
9
+ paras = message.split("\n\n")
10
+
11
+ paras.map! do |unwrapped|
12
+ words = unwrapped.split(" ")
13
+ counter = words.first.length
14
+ words.inject do |memo, word|
15
+ word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n")
16
+ counter = 0 if word.include? "\n"
17
+ if (counter + word.length + 1) < width
18
+ memo = "#{memo} #{word}"
19
+ counter += (word.length + 1)
20
+ else
21
+ memo = "#{memo}\n#{word}"
22
+ counter = word.length
23
+ end
24
+ memo
25
+ end
26
+ end.compact!
27
+
28
+ paras.each do |para|
29
+ para.split("\n").each do |line|
30
+ stdout.puts line.insert(0, " " * @indent)
31
+ end
32
+ stdout.puts unless para == paras.last
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -75,7 +75,7 @@ class Bundler::Thor
75
75
  # Allow shell to be shared between invocations.
76
76
  #
77
77
  def _shared_configuration #:nodoc:
78
- super.merge!(:shell => shell)
78
+ super.merge!(shell: shell)
79
79
  end
80
80
  end
81
81
  end
@@ -90,7 +90,7 @@ class Bundler::Thor
90
90
  def snake_case(str)
91
91
  return str.downcase if str =~ /^[A-Z_]+$/
92
92
  str.gsub(/\B[A-Z]/, '_\&').squeeze("_") =~ /_*(.*)/
93
- $+.downcase
93
+ Regexp.last_match(-1).downcase
94
94
  end
95
95
 
96
96
  # Receives a string and convert it to camel case. camel_case returns CamelCase.
@@ -130,9 +130,10 @@ class Bundler::Thor
130
130
  #
131
131
  def find_class_and_command_by_namespace(namespace, fallback = true)
132
132
  if namespace.include?(":") # look for a namespaced command
133
- pieces = namespace.split(":")
134
- command = pieces.pop
135
- klass = Bundler::Thor::Util.find_by_namespace(pieces.join(":"))
133
+ *pieces, command = namespace.split(":")
134
+ namespace = pieces.join(":")
135
+ namespace = "default" if namespace.empty?
136
+ klass = Bundler::Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.commands.keys.include?(command) }
136
137
  end
137
138
  unless klass # look for a Bundler::Thor::Group with the right name
138
139
  klass = Bundler::Thor::Util.find_by_namespace(namespace)
@@ -150,7 +151,7 @@ class Bundler::Thor
150
151
  # inside the sandbox to avoid namespacing conflicts.
151
152
  #
152
153
  def load_thorfile(path, content = nil, debug = false)
153
- content ||= File.binread(path)
154
+ content ||= File.read(path)
154
155
 
155
156
  begin
156
157
  Bundler::Thor::Sandbox.class_eval(content, path)
@@ -189,7 +190,7 @@ class Bundler::Thor
189
190
  # Returns the root where thor files are located, depending on the OS.
190
191
  #
191
192
  def thor_root
192
- File.join(user_home, ".thor").tr('\\', "/")
193
+ File.join(user_home, ".thor").tr("\\", "/")
193
194
  end
194
195
 
195
196
  # Returns the files in the thor root. On Windows thor_root will be something
@@ -236,7 +237,7 @@ class Bundler::Thor
236
237
  # symlink points to 'ruby_install_name'
237
238
  ruby = alternate_ruby if linked_ruby == ruby_name || linked_ruby == ruby
238
239
  end
239
- rescue NotImplementedError # rubocop:disable HandleExceptions
240
+ rescue NotImplementedError # rubocop:disable Lint/HandleExceptions
240
241
  # just ignore on windows
241
242
  end
242
243
  end
@@ -1,3 +1,3 @@
1
1
  class Bundler::Thor
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end