bundler 1.13.6 → 1.17.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

Files changed (323) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +554 -9
  3. data/README.md +28 -5
  4. data/bundler.gemspec +40 -11
  5. data/exe/bundle +4 -8
  6. data/exe/bundle_ruby +4 -3
  7. data/lib/bundler.rb +162 -68
  8. data/lib/bundler/build_metadata.rb +53 -0
  9. data/lib/bundler/capistrano.rb +5 -0
  10. data/lib/bundler/cli.rb +360 -118
  11. data/lib/bundler/cli/add.rb +35 -0
  12. data/lib/bundler/cli/binstubs.rb +18 -10
  13. data/lib/bundler/cli/cache.rb +6 -5
  14. data/lib/bundler/cli/check.rb +4 -6
  15. data/lib/bundler/cli/clean.rb +6 -7
  16. data/lib/bundler/cli/common.rb +47 -1
  17. data/lib/bundler/cli/config.rb +26 -7
  18. data/lib/bundler/cli/console.rb +2 -1
  19. data/lib/bundler/cli/doctor.rb +63 -18
  20. data/lib/bundler/cli/exec.rb +12 -5
  21. data/lib/bundler/cli/gem.rb +59 -21
  22. data/lib/bundler/cli/info.rb +50 -0
  23. data/lib/bundler/cli/init.rb +21 -7
  24. data/lib/bundler/cli/inject.rb +13 -4
  25. data/lib/bundler/cli/install.rb +72 -101
  26. data/lib/bundler/cli/issue.rb +40 -0
  27. data/lib/bundler/cli/list.rb +58 -0
  28. data/lib/bundler/cli/lock.rb +9 -6
  29. data/lib/bundler/cli/open.rb +4 -3
  30. data/lib/bundler/cli/outdated.rb +175 -60
  31. data/lib/bundler/cli/package.rb +9 -6
  32. data/lib/bundler/cli/platform.rb +2 -1
  33. data/lib/bundler/cli/plugin.rb +1 -0
  34. data/lib/bundler/cli/pristine.rb +47 -0
  35. data/lib/bundler/cli/remove.rb +18 -0
  36. data/lib/bundler/cli/show.rb +2 -2
  37. data/lib/bundler/cli/update.rb +44 -34
  38. data/lib/bundler/cli/viz.rb +5 -1
  39. data/lib/bundler/compact_index_client.rb +109 -0
  40. data/lib/bundler/compact_index_client/cache.rb +118 -0
  41. data/lib/bundler/compact_index_client/updater.rb +116 -0
  42. data/lib/bundler/compatibility_guard.rb +14 -0
  43. data/lib/bundler/constants.rb +1 -0
  44. data/lib/bundler/current_ruby.rb +17 -8
  45. data/lib/bundler/definition.rb +353 -182
  46. data/lib/bundler/dep_proxy.rb +3 -1
  47. data/lib/bundler/dependency.rb +22 -10
  48. data/lib/bundler/deployment.rb +1 -1
  49. data/lib/bundler/deprecate.rb +15 -3
  50. data/lib/bundler/dsl.rb +122 -64
  51. data/lib/bundler/endpoint_specification.rb +13 -3
  52. data/lib/bundler/env.rb +110 -38
  53. data/lib/bundler/environment_preserver.rb +27 -6
  54. data/lib/bundler/errors.rb +24 -0
  55. data/lib/bundler/feature_flag.rb +74 -0
  56. data/lib/bundler/fetcher.rb +18 -11
  57. data/lib/bundler/fetcher/base.rb +1 -0
  58. data/lib/bundler/fetcher/compact_index.rb +7 -5
  59. data/lib/bundler/fetcher/dependency.rb +3 -2
  60. data/lib/bundler/fetcher/downloader.rb +25 -7
  61. data/lib/bundler/fetcher/index.rb +3 -2
  62. data/lib/bundler/friendly_errors.rb +33 -7
  63. data/lib/bundler/gem_helper.rb +25 -11
  64. data/lib/bundler/gem_helpers.rb +70 -1
  65. data/lib/bundler/gem_remote_fetcher.rb +1 -0
  66. data/lib/bundler/gem_tasks.rb +1 -0
  67. data/lib/bundler/gem_version_promoter.rb +17 -2
  68. data/lib/bundler/gemdeps.rb +29 -0
  69. data/lib/bundler/graph.rb +1 -0
  70. data/lib/bundler/index.rb +28 -15
  71. data/lib/bundler/injector.rb +216 -33
  72. data/lib/bundler/inline.rb +12 -12
  73. data/lib/bundler/installer.rb +139 -53
  74. data/lib/bundler/installer/gem_installer.rb +15 -5
  75. data/lib/bundler/installer/parallel_installer.rb +113 -28
  76. data/lib/bundler/installer/standalone.rb +1 -0
  77. data/lib/bundler/lazy_specification.rb +31 -3
  78. data/lib/bundler/lockfile_generator.rb +95 -0
  79. data/lib/bundler/lockfile_parser.rb +50 -37
  80. data/lib/bundler/match_platform.rb +13 -3
  81. data/lib/bundler/mirror.rb +10 -5
  82. data/lib/bundler/plugin.rb +22 -8
  83. data/lib/bundler/plugin/api.rb +2 -1
  84. data/lib/bundler/plugin/api/source.rb +17 -4
  85. data/lib/bundler/plugin/events.rb +61 -0
  86. data/lib/bundler/plugin/index.rb +9 -2
  87. data/lib/bundler/plugin/installer.rb +7 -6
  88. data/lib/bundler/plugin/source_list.rb +7 -8
  89. data/lib/bundler/process_lock.rb +24 -0
  90. data/lib/bundler/psyched_yaml.rb +10 -0
  91. data/lib/bundler/remote_specification.rb +30 -1
  92. data/lib/bundler/resolver.rb +187 -194
  93. data/lib/bundler/resolver/spec_group.rb +106 -0
  94. data/lib/bundler/retry.rb +5 -1
  95. data/lib/bundler/ruby_dsl.rb +1 -0
  96. data/lib/bundler/ruby_version.rb +12 -2
  97. data/lib/bundler/rubygems_ext.rb +23 -8
  98. data/lib/bundler/rubygems_gem_installer.rb +90 -0
  99. data/lib/bundler/rubygems_integration.rb +193 -70
  100. data/lib/bundler/runtime.rb +39 -22
  101. data/lib/bundler/settings.rb +245 -85
  102. data/lib/bundler/settings/validator.rb +102 -0
  103. data/lib/bundler/setup.rb +4 -7
  104. data/lib/bundler/shared_helpers.rb +183 -40
  105. data/lib/bundler/similarity_detector.rb +1 -0
  106. data/lib/bundler/source.rb +58 -1
  107. data/lib/bundler/source/gemspec.rb +1 -0
  108. data/lib/bundler/source/git.rb +52 -23
  109. data/lib/bundler/source/git/git_proxy.rb +30 -14
  110. data/lib/bundler/source/metadata.rb +62 -0
  111. data/lib/bundler/source/path.rb +42 -16
  112. data/lib/bundler/source/path/installer.rb +4 -2
  113. data/lib/bundler/source/rubygems.rb +171 -82
  114. data/lib/bundler/source/rubygems/remote.rb +12 -2
  115. data/lib/bundler/source_list.rb +75 -15
  116. data/lib/bundler/spec_set.rb +67 -32
  117. data/lib/bundler/ssl_certs/certificate_manager.rb +2 -1
  118. data/lib/bundler/stub_specification.rb +86 -2
  119. data/lib/bundler/templates/.document +1 -0
  120. data/lib/bundler/templates/Executable +13 -1
  121. data/lib/bundler/templates/Executable.bundler +105 -0
  122. data/lib/bundler/templates/Executable.standalone +5 -5
  123. data/lib/bundler/templates/Gemfile +3 -0
  124. data/lib/bundler/templates/gems.rb +8 -0
  125. data/lib/bundler/templates/newgem/Gemfile.tt +4 -2
  126. data/lib/bundler/templates/newgem/LICENSE.txt.tt +1 -1
  127. data/lib/bundler/templates/newgem/README.md.tt +14 -8
  128. data/lib/bundler/templates/newgem/Rakefile.tt +5 -5
  129. data/lib/bundler/templates/newgem/bin/console.tt +1 -1
  130. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +4 -4
  131. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +3 -3
  132. data/lib/bundler/templates/newgem/gitignore.tt +5 -1
  133. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +7 -6
  134. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +4 -4
  135. data/lib/bundler/templates/newgem/newgem.gemspec.tt +21 -12
  136. data/lib/bundler/templates/newgem/rspec.tt +1 -0
  137. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +1 -3
  138. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +13 -1
  139. data/lib/bundler/templates/newgem/test/newgem_test.rb.tt +1 -1
  140. data/lib/bundler/templates/newgem/test/test_helper.rb.tt +3 -3
  141. data/lib/bundler/templates/newgem/{.travis.yml.tt → travis.yml.tt} +2 -0
  142. data/lib/bundler/ui.rb +1 -0
  143. data/lib/bundler/ui/rg_proxy.rb +1 -0
  144. data/lib/bundler/ui/shell.rb +30 -10
  145. data/lib/bundler/ui/silent.rb +21 -1
  146. data/lib/bundler/uri_credentials_filter.rb +1 -0
  147. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1638 -0
  148. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +2 -0
  149. data/lib/bundler/vendor/molinillo/lib/molinillo/compatibility.rb +26 -0
  150. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +7 -0
  151. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +1 -0
  152. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +26 -6
  153. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +2 -1
  154. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +12 -4
  155. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +3 -2
  156. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +63 -0
  157. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +11 -3
  158. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +13 -1
  159. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +3 -2
  160. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +3 -2
  161. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +18 -5
  162. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +75 -7
  163. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +2 -1
  164. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +1 -0
  165. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +3 -1
  166. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +499 -128
  167. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +1 -0
  168. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +8 -4
  169. data/lib/bundler/vendor/{net → net-http-persistent/lib/net}/http/faster.rb +1 -0
  170. data/lib/bundler/vendor/{net → net-http-persistent/lib/net}/http/persistent.rb +27 -24
  171. data/lib/bundler/vendor/{net → net-http-persistent/lib/net}/http/persistent/ssl_reuse.rb +2 -1
  172. data/lib/bundler/vendor/thor/lib/thor.rb +46 -21
  173. data/lib/bundler/vendor/thor/lib/thor/actions.rb +24 -22
  174. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +2 -1
  175. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +2 -1
  176. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +2 -2
  177. data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +16 -8
  178. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +66 -18
  179. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +17 -15
  180. data/lib/bundler/vendor/thor/lib/thor/base.rb +55 -32
  181. data/lib/bundler/vendor/thor/lib/thor/command.rb +13 -11
  182. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +21 -1
  183. data/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +7 -5
  184. data/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +94 -63
  185. data/lib/bundler/vendor/thor/lib/thor/error.rb +3 -3
  186. data/lib/bundler/vendor/thor/lib/thor/group.rb +13 -13
  187. data/lib/bundler/vendor/thor/lib/thor/invocation.rb +4 -5
  188. data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +2 -0
  189. data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +4 -7
  190. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +16 -16
  191. data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +42 -21
  192. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +13 -10
  193. data/lib/bundler/vendor/thor/lib/thor/runner.rb +31 -29
  194. data/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  195. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +49 -33
  196. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +1 -1
  197. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +4 -4
  198. data/lib/bundler/vendor/thor/lib/thor/util.rb +8 -7
  199. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  200. data/lib/bundler/vendored_fileutils.rb +9 -0
  201. data/lib/bundler/vendored_molinillo.rb +1 -0
  202. data/lib/bundler/vendored_persistent.rb +43 -3
  203. data/lib/bundler/vendored_thor.rb +6 -2
  204. data/lib/bundler/version.rb +19 -2
  205. data/lib/bundler/version_ranges.rb +76 -0
  206. data/lib/bundler/vlad.rb +5 -0
  207. data/lib/bundler/worker.rb +30 -6
  208. data/lib/bundler/yaml_serializer.rb +4 -4
  209. data/man/bundle-add.1 +58 -0
  210. data/man/bundle-add.1.txt +52 -0
  211. data/man/bundle-add.ronn +40 -0
  212. data/{lib/bundler/man/bundle-binstubs → man/bundle-binstubs.1} +11 -1
  213. data/man/bundle-binstubs.1.txt +48 -0
  214. data/man/bundle-binstubs.ronn +15 -1
  215. data/man/bundle-check.1 +31 -0
  216. data/man/bundle-check.1.txt +33 -0
  217. data/man/bundle-check.ronn +26 -0
  218. data/man/bundle-clean.1 +24 -0
  219. data/man/bundle-clean.1.txt +26 -0
  220. data/man/bundle-clean.ronn +18 -0
  221. data/man/bundle-config.1 +497 -0
  222. data/man/bundle-config.1.txt +529 -0
  223. data/man/bundle-config.ronn +233 -61
  224. data/man/bundle-doctor.1 +44 -0
  225. data/man/bundle-doctor.1.txt +44 -0
  226. data/man/bundle-doctor.ronn +33 -0
  227. data/{lib/bundler/man/bundle-exec → man/bundle-exec.1} +6 -3
  228. data/man/bundle-exec.1.txt +178 -0
  229. data/man/bundle-exec.ronn +10 -3
  230. data/{lib/bundler/man/bundle-gem → man/bundle-gem.1} +4 -4
  231. data/man/bundle-gem.1.txt +91 -0
  232. data/man/bundle-gem.ronn +3 -2
  233. data/man/bundle-info.1 +20 -0
  234. data/man/bundle-info.1.txt +21 -0
  235. data/man/bundle-info.ronn +17 -0
  236. data/man/bundle-init.1 +25 -0
  237. data/man/bundle-init.1.txt +34 -0
  238. data/man/bundle-init.ronn +29 -0
  239. data/man/bundle-inject.1 +33 -0
  240. data/man/bundle-inject.1.txt +32 -0
  241. data/man/bundle-inject.ronn +22 -0
  242. data/{lib/bundler/man/bundle-install → man/bundle-install.1} +32 -29
  243. data/man/bundle-install.1.txt +396 -0
  244. data/man/bundle-install.ronn +45 -36
  245. data/man/bundle-list.1 +50 -0
  246. data/man/bundle-list.1.txt +43 -0
  247. data/man/bundle-list.ronn +33 -0
  248. data/{lib/bundler/man/bundle-lock → man/bundle-lock.1} +43 -2
  249. data/man/bundle-lock.1.txt +93 -0
  250. data/man/bundle-lock.ronn +47 -0
  251. data/man/bundle-open.1 +32 -0
  252. data/man/bundle-open.1.txt +29 -0
  253. data/man/bundle-open.ronn +19 -0
  254. data/man/bundle-outdated.1 +155 -0
  255. data/man/bundle-outdated.1.txt +131 -0
  256. data/man/bundle-outdated.ronn +111 -0
  257. data/{lib/bundler/man/bundle-package → man/bundle-package.1} +6 -3
  258. data/man/bundle-package.1.txt +79 -0
  259. data/man/bundle-package.ronn +7 -2
  260. data/{lib/bundler/man/bundle-platform → man/bundle-platform.1} +1 -1
  261. data/man/bundle-platform.1.txt +57 -0
  262. data/man/bundle-pristine.1 +34 -0
  263. data/man/bundle-pristine.1.txt +44 -0
  264. data/man/bundle-pristine.ronn +34 -0
  265. data/man/bundle-remove.1 +31 -0
  266. data/man/bundle-remove.1.txt +34 -0
  267. data/man/bundle-remove.ronn +23 -0
  268. data/man/bundle-show.1 +23 -0
  269. data/man/bundle-show.1.txt +27 -0
  270. data/man/bundle-show.ronn +21 -0
  271. data/man/bundle-update.1 +394 -0
  272. data/man/bundle-update.1.txt +391 -0
  273. data/man/bundle-update.ronn +172 -16
  274. data/man/bundle-viz.1 +39 -0
  275. data/man/bundle-viz.1.txt +39 -0
  276. data/man/bundle-viz.ronn +30 -0
  277. data/{lib/bundler/man/bundle → man/bundle.1} +44 -28
  278. data/man/bundle.1.txt +116 -0
  279. data/man/bundle.ronn +39 -27
  280. data/{lib/bundler/man → man}/gemfile.5 +67 -84
  281. data/man/gemfile.5.ronn +77 -55
  282. data/man/gemfile.5.txt +653 -0
  283. data/man/index.txt +25 -8
  284. metadata +118 -58
  285. data/.codeclimate.yml +0 -25
  286. data/.gitignore +0 -16
  287. data/.rspec +0 -3
  288. data/.rubocop.yml +0 -128
  289. data/.rubocop_todo.yml +0 -248
  290. data/.travis.yml +0 -108
  291. data/CODE_OF_CONDUCT.md +0 -42
  292. data/CONTRIBUTING.md +0 -36
  293. data/DEVELOPMENT.md +0 -148
  294. data/ISSUES.md +0 -100
  295. data/Rakefile +0 -333
  296. data/bin/rake +0 -19
  297. data/bin/rspec +0 -15
  298. data/bin/rubocop +0 -17
  299. data/bin/with_rubygems +0 -39
  300. data/lib/bundler/man/bundle-binstubs.txt +0 -33
  301. data/lib/bundler/man/bundle-config +0 -254
  302. data/lib/bundler/man/bundle-config.txt +0 -282
  303. data/lib/bundler/man/bundle-exec.txt +0 -171
  304. data/lib/bundler/man/bundle-gem.txt +0 -90
  305. data/lib/bundler/man/bundle-install.txt +0 -385
  306. data/lib/bundler/man/bundle-lock.txt +0 -52
  307. data/lib/bundler/man/bundle-package.txt +0 -74
  308. data/lib/bundler/man/bundle-platform.txt +0 -57
  309. data/lib/bundler/man/bundle-update +0 -221
  310. data/lib/bundler/man/bundle-update.txt +0 -227
  311. data/lib/bundler/man/bundle.txt +0 -104
  312. data/lib/bundler/man/gemfile.5.txt +0 -636
  313. data/lib/bundler/postit_trampoline.rb +0 -68
  314. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb +0 -79
  315. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb +0 -112
  316. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb +0 -80
  317. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb +0 -4
  318. data/lib/bundler/vendor/postit/lib/postit.rb +0 -15
  319. data/lib/bundler/vendor/postit/lib/postit/environment.rb +0 -44
  320. data/lib/bundler/vendor/postit/lib/postit/installer.rb +0 -28
  321. data/lib/bundler/vendor/postit/lib/postit/parser.rb +0 -21
  322. data/lib/bundler/vendor/postit/lib/postit/setup.rb +0 -12
  323. data/lib/bundler/vendor/postit/lib/postit/version.rb +0 -3
@@ -58,6 +58,7 @@ class Bundler::Thor
58
58
 
59
59
  def invoke!
60
60
  invoke_with_conflict_check do
61
+ require "fileutils"
61
62
  FileUtils.mkdir_p(File.dirname(destination))
62
63
  File.open(destination, "wb") { |f| f.write render }
63
64
  end
@@ -84,7 +85,7 @@ class Bundler::Thor
84
85
  def force_or_skip_or_conflict(force, skip, &block)
85
86
  if force
86
87
  say_status :force, :yellow
87
- block.call unless pretend?
88
+ yield unless pretend?
88
89
  elsif skip
89
90
  say_status :skip, :yellow
90
91
  else
@@ -14,7 +14,7 @@ class Bundler::Thor
14
14
  #
15
15
  # create_link "config/apache.conf", "/etc/apache.conf"
16
16
  #
17
- def create_link(destination, *args, &block)
17
+ def create_link(destination, *args)
18
18
  config = args.last.is_a?(Hash) ? args.pop : {}
19
19
  source = args.first
20
20
  action CreateLink.new(self, destination, source, config)
@@ -38,6 +38,7 @@ class Bundler::Thor
38
38
 
39
39
  def invoke!
40
40
  invoke_with_conflict_check do
41
+ require "fileutils"
41
42
  FileUtils.mkdir_p(File.dirname(destination))
42
43
  # Create a symlink by default
43
44
  config[:symbolic] = true if config[:symbolic].nil?
@@ -72,7 +72,7 @@ class Bundler::Thor
72
72
 
73
73
  protected
74
74
 
75
- def execute! # rubocop:disable MethodLength
75
+ def execute!
76
76
  lookup = Util.escape_globs(source)
77
77
  lookup = config[:recursive] ? File.join(lookup, "**") : lookup
78
78
  lookup = file_level_lookup(lookup)
@@ -85,7 +85,7 @@ class Bundler::Thor
85
85
 
86
86
  case file_source
87
87
  when /\.empty_directory$/
88
- dirname = File.dirname(file_destination).gsub(/\/\.$/, "")
88
+ dirname = File.dirname(file_destination).gsub(%r{/\.$}, "")
89
89
  next if dirname == given_destination
90
90
  base.empty_directory(dirname, config)
91
91
  when /#{TEMPLATE_EXTNAME}$/
@@ -32,7 +32,8 @@ class Bundler::Thor
32
32
  # config<Hash>:: give :verbose => false to not log the status.
33
33
  #
34
34
  def initialize(base, destination, config = {})
35
- @base, @config = base, {:verbose => true}.merge(config)
35
+ @base = base
36
+ @config = {:verbose => true}.merge(config)
36
37
  self.destination = destination
37
38
  end
38
39
 
@@ -47,12 +48,14 @@ class Bundler::Thor
47
48
 
48
49
  def invoke!
49
50
  invoke_with_conflict_check do
51
+ require "fileutils"
50
52
  ::FileUtils.mkdir_p(destination)
51
53
  end
52
54
  end
53
55
 
54
56
  def revoke!
55
57
  say_status :remove, :red
58
+ require "fileutils"
56
59
  ::FileUtils.rm_rf(destination) if !pretend? && exists?
57
60
  given_destination
58
61
  end
@@ -80,11 +83,10 @@ class Bundler::Thor
80
83
  # given_destination #=> baz
81
84
  #
82
85
  def destination=(destination)
83
- if destination
84
- @given_destination = convert_encoded_instructions(destination.to_s)
85
- @destination = ::File.expand_path(@given_destination, base.destination_root)
86
- @relative_destination = base.relative_to_original_destination_root(@destination)
87
- end
86
+ return unless destination
87
+ @given_destination = convert_encoded_instructions(destination.to_s)
88
+ @destination = ::File.expand_path(@given_destination, base.destination_root)
89
+ @relative_destination = base.relative_to_original_destination_root(@destination)
88
90
  end
89
91
 
90
92
  # Filenames in the encoded form are converted. If you have a file:
@@ -112,16 +114,22 @@ class Bundler::Thor
112
114
  if exists?
113
115
  on_conflict_behavior(&block)
114
116
  else
117
+ yield unless pretend?
115
118
  say_status :create, :green
116
- block.call unless pretend?
117
119
  end
118
120
 
119
121
  destination
122
+ rescue Errno::EISDIR, Errno::EEXIST
123
+ on_file_clash_behavior
124
+ end
125
+
126
+ def on_file_clash_behavior
127
+ say_status :file_clash, :red
120
128
  end
121
129
 
122
130
  # What to do when the destination file already exists.
123
131
  #
124
- def on_conflict_behavior(&block)
132
+ def on_conflict_behavior
125
133
  say_status :exist, :blue
126
134
  end
127
135
 
@@ -1,5 +1,4 @@
1
1
  require "erb"
2
- require "open-uri"
3
2
 
4
3
  class Bundler::Thor
5
4
  module Actions
@@ -26,7 +25,7 @@ class Bundler::Thor
26
25
 
27
26
  create_file destination, nil, config do
28
27
  content = File.binread(source)
29
- content = block.call(content) if block
28
+ content = yield(content) if block
30
29
  content
31
30
  end
32
31
  if config[:mode] == :preserve
@@ -49,7 +48,7 @@ class Bundler::Thor
49
48
  #
50
49
  # link_file "doc/README"
51
50
  #
52
- def link_file(source, *args, &block)
51
+ def link_file(source, *args)
53
52
  config = args.last.is_a?(Hash) ? args.pop : {}
54
53
  destination = args.first || source
55
54
  source = File.expand_path(find_in_source_paths(source.to_s))
@@ -78,11 +77,16 @@ class Bundler::Thor
78
77
  config = args.last.is_a?(Hash) ? args.pop : {}
79
78
  destination = args.first
80
79
 
81
- source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ %r{^https?\://}
80
+ if source =~ %r{^https?\://}
81
+ require "open-uri"
82
+ else
83
+ source = File.expand_path(find_in_source_paths(source.to_s))
84
+ end
85
+
82
86
  render = open(source) { |input| input.binmode.read }
83
87
 
84
88
  destination ||= if block_given?
85
- block.arity == 1 ? block.call(render) : block.call
89
+ block.arity == 1 ? yield(render) : yield
86
90
  else
87
91
  File.basename(source)
88
92
  end
@@ -110,11 +114,13 @@ class Bundler::Thor
110
114
  destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/, "")
111
115
 
112
116
  source = File.expand_path(find_in_source_paths(source.to_s))
113
- context = instance_eval("binding")
117
+ context = config.delete(:context) || instance_eval("binding")
114
118
 
115
119
  create_file destination, nil, config do
116
- content = ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
117
- content = block.call(content) if block
120
+ content = CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer").tap do |erb|
121
+ erb.filename = source
122
+ end.result(context)
123
+ content = yield(content) if block
118
124
  content
119
125
  end
120
126
  end
@@ -134,7 +140,10 @@ class Bundler::Thor
134
140
  return unless behavior == :invoke
135
141
  path = File.expand_path(path, destination_root)
136
142
  say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
137
- FileUtils.chmod_R(mode, path) unless options[:pretend]
143
+ unless options[:pretend]
144
+ require "fileutils"
145
+ FileUtils.chmod_R(mode, path)
146
+ end
138
147
  end
139
148
 
140
149
  # Prepend text to a file. Since it depends on insert_into_file, it's reversible.
@@ -154,7 +163,7 @@ class Bundler::Thor
154
163
  #
155
164
  def prepend_to_file(path, *args, &block)
156
165
  config = args.last.is_a?(Hash) ? args.pop : {}
157
- config.merge!(:after => /\A/)
166
+ config[:after] = /\A/
158
167
  insert_into_file(path, *(args << config), &block)
159
168
  end
160
169
  alias_method :prepend_file, :prepend_to_file
@@ -176,7 +185,7 @@ class Bundler::Thor
176
185
  #
177
186
  def append_to_file(path, *args, &block)
178
187
  config = args.last.is_a?(Hash) ? args.pop : {}
179
- config.merge!(:before => /\z/)
188
+ config[:before] = /\z/
180
189
  insert_into_file(path, *(args << config), &block)
181
190
  end
182
191
  alias_method :append_file, :append_to_file
@@ -200,7 +209,30 @@ class Bundler::Thor
200
209
  #
201
210
  def inject_into_class(path, klass, *args, &block)
202
211
  config = args.last.is_a?(Hash) ? args.pop : {}
203
- config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/)
212
+ config[:after] = /class #{klass}\n|class #{klass} .*\n/
213
+ insert_into_file(path, *(args << config), &block)
214
+ end
215
+
216
+ # Injects text right after the module definition. Since it depends on
217
+ # insert_into_file, it's reversible.
218
+ #
219
+ # ==== Parameters
220
+ # path<String>:: path of the file to be changed
221
+ # module_name<String|Class>:: the module to be manipulated
222
+ # data<String>:: the data to append to the class, can be also given as a block.
223
+ # config<Hash>:: give :verbose => false to not log the status.
224
+ #
225
+ # ==== Examples
226
+ #
227
+ # inject_into_module "app/helpers/application_helper.rb", ApplicationHelper, " def help; 'help'; end\n"
228
+ #
229
+ # inject_into_module "app/helpers/application_helper.rb", ApplicationHelper do
230
+ # " def help; 'help'; end\n"
231
+ # end
232
+ #
233
+ def inject_into_module(path, module_name, *args, &block)
234
+ config = args.last.is_a?(Hash) ? args.pop : {}
235
+ config[:after] = /module #{module_name}\n|module #{module_name} .*\n/
204
236
  insert_into_file(path, *(args << config), &block)
205
237
  end
206
238
 
@@ -285,10 +317,13 @@ class Bundler::Thor
285
317
  #
286
318
  def remove_file(path, config = {})
287
319
  return unless behavior == :invoke
288
- path = File.expand_path(path, destination_root)
320
+ path = File.expand_path(path, destination_root)
289
321
 
290
322
  say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
291
- ::FileUtils.rm_rf(path) if !options[:pretend] && File.exist?(path)
323
+ if !options[:pretend] && File.exist?(path)
324
+ require "fileutils"
325
+ ::FileUtils.rm_rf(path)
326
+ end
292
327
  end
293
328
  alias_method :remove_dir, :remove_file
294
329
 
@@ -301,16 +336,29 @@ class Bundler::Thor
301
336
  @output_buffer.concat(string)
302
337
  end
303
338
 
304
- def capture(*args, &block)
305
- with_output_buffer { block.call(*args) }
339
+ def capture(*args)
340
+ with_output_buffer { yield(*args) }
306
341
  end
307
342
 
308
- def with_output_buffer(buf = "") #:nodoc:
309
- self.output_buffer, old_buffer = buf, output_buffer
343
+ def with_output_buffer(buf = "".dup) #:nodoc:
344
+ raise ArgumentError, "Buffer can not be a frozen object" if buf.frozen?
345
+ old_buffer = output_buffer
346
+ self.output_buffer = buf
310
347
  yield
311
348
  output_buffer
312
349
  ensure
313
350
  self.output_buffer = old_buffer
314
351
  end
352
+
353
+ # Bundler::Thor::Actions#capture depends on what kind of buffer is used in ERB.
354
+ # Thus CapturableERB fixes ERB to use String buffer.
355
+ class CapturableERB < ERB
356
+ def set_eoutvar(compiler, eoutvar = "_erbout")
357
+ compiler.put_cmd = "#{eoutvar}.concat"
358
+ compiler.insert_cmd = "#{eoutvar}.concat"
359
+ compiler.pre_cmd = ["#{eoutvar} = ''.dup"]
360
+ compiler.post_cmd = [eoutvar]
361
+ end
362
+ end
315
363
  end
316
364
  end
@@ -22,11 +22,8 @@ class Bundler::Thor
22
22
  # end
23
23
  #
24
24
  def insert_into_file(destination, *args, &block)
25
- if block_given?
26
- data, config = block, args.shift
27
- else
28
- data, config = args.shift, args.shift
29
- end
25
+ data = block_given? ? block : args.shift
26
+ config = args.shift
30
27
  action InjectIntoFile.new(self, destination, data, config)
31
28
  end
32
29
  alias_method :inject_into_file, :insert_into_file
@@ -39,9 +36,9 @@ class Bundler::Thor
39
36
 
40
37
  @behavior, @flag = if @config.key?(:after)
41
38
  [:after, @config.delete(:after)]
42
- else
43
- [:before, @config.delete(:before)]
44
- end
39
+ else
40
+ [:before, @config.delete(:before)]
41
+ end
45
42
 
46
43
  @replacement = data.is_a?(Proc) ? data.call : data
47
44
  @flag = Regexp.escape(@flag) unless @flag.is_a?(Regexp)
@@ -56,7 +53,13 @@ class Bundler::Thor
56
53
  replacement + '\0'
57
54
  end
58
55
 
59
- replace!(/#{flag}/, content, config[:force])
56
+ if exists?
57
+ replace!(/#{flag}/, content, config[:force])
58
+ else
59
+ unless pretend?
60
+ raise Bundler::Thor::Error, "The file #{ destination } does not appear to exist"
61
+ end
62
+ end
60
63
  end
61
64
 
62
65
  def revoke!
@@ -94,12 +97,11 @@ class Bundler::Thor
94
97
  # Adds the content to the file.
95
98
  #
96
99
  def replace!(regexp, string, force)
97
- unless base.options[:pretend]
98
- content = File.binread(destination)
99
- if force || !content.include?(replacement)
100
- content.gsub!(regexp, string)
101
- File.open(destination, "wb") { |file| file.write(content) }
102
- end
100
+ return if pretend?
101
+ content = File.read(destination)
102
+ if force || !content.include?(replacement)
103
+ content.gsub!(regexp, string)
104
+ File.open(destination, "wb") { |file| file.write(content) }
103
105
  end
104
106
  end
105
107
  end
@@ -14,11 +14,11 @@ class Bundler::Thor
14
14
  autoload :Group, "bundler/vendor/thor/lib/thor/group"
15
15
 
16
16
  # Shortcuts for help.
17
- HELP_MAPPINGS = %w[-h -? --help -D]
17
+ HELP_MAPPINGS = %w(-h -? --help -D)
18
18
 
19
19
  # Bundler::Thor methods that should not be overwritten by the user.
20
- THOR_RESERVED_WORDS = %w[invoke shell options behavior root destination_root relative_root
21
- action add_file create_file in_root inside run run_ruby_script]
20
+ THOR_RESERVED_WORDS = %w(invoke shell options behavior root destination_root relative_root
21
+ action add_file create_file in_root inside run run_ruby_script)
22
22
 
23
23
  TEMPLATE_EXTNAME = ".tt"
24
24
 
@@ -41,7 +41,7 @@ class Bundler::Thor
41
41
  #
42
42
  # config<Hash>:: Configuration for this Bundler::Thor class.
43
43
  #
44
- def initialize(args = [], local_options = {}, config = {}) # rubocop:disable MethodLength
44
+ def initialize(args = [], local_options = {}, config = {})
45
45
  parse_options = self.class.class_options
46
46
 
47
47
  # The start method splits inbound arguments at the first argument
@@ -52,18 +52,21 @@ class Bundler::Thor
52
52
  command_options = config.delete(:command_options) # hook for start
53
53
  parse_options = parse_options.merge(command_options) if command_options
54
54
  if local_options.is_a?(Array)
55
- array_options, hash_options = local_options, {}
55
+ array_options = local_options
56
+ hash_options = {}
56
57
  else
57
58
  # Handle the case where the class was explicitly instantiated
58
59
  # with pre-parsed options.
59
- array_options, hash_options = [], local_options
60
+ array_options = []
61
+ hash_options = local_options
60
62
  end
61
63
 
62
64
  # Let Bundler::Thor::Options parse the options first, so it can remove
63
65
  # declared options from the array. This will leave us with
64
66
  # a list of arguments that weren't declared.
65
67
  stop_on_unknown = self.class.stop_on_unknown_option? config[:current_command]
66
- opts = Bundler::Thor::Options.new(parse_options, hash_options, stop_on_unknown)
68
+ disable_required_check = self.class.disable_required_check? config[:current_command]
69
+ opts = Bundler::Thor::Options.new(parse_options, hash_options, stop_on_unknown, disable_required_check)
67
70
  self.options = opts.parse(array_options)
68
71
  self.options = config[:class_options].merge(options) if config[:class_options]
69
72
 
@@ -148,6 +151,21 @@ class Bundler::Thor
148
151
  !!check_unknown_options
149
152
  end
150
153
 
154
+ # If you want to raise an error when the default value of an option does not match
155
+ # the type call check_default_type!
156
+ # This is disabled by default for compatibility.
157
+ def check_default_type!
158
+ @check_default_type = true
159
+ end
160
+
161
+ def check_default_type #:nodoc:
162
+ @check_default_type ||= from_superclass(:check_default_type, false)
163
+ end
164
+
165
+ def check_default_type? #:nodoc:
166
+ !!check_default_type
167
+ end
168
+
151
169
  # If true, option parsing is suspended as soon as an unknown option or a
152
170
  # regular argument is encountered. All remaining arguments are passed to
153
171
  # the command as regular arguments.
@@ -155,6 +173,12 @@ class Bundler::Thor
155
173
  false
156
174
  end
157
175
 
176
+ # If true, option set will not suspend the execution of the command when
177
+ # a required option is not provided.
178
+ def disable_required_check?(command_name) #:nodoc:
179
+ false
180
+ end
181
+
158
182
  # If you want only strict string args (useful when cascading thor classes),
159
183
  # call strict_args_position! This is disabled by default to allow dynamic
160
184
  # invocations.
@@ -205,7 +229,7 @@ class Bundler::Thor
205
229
  # ==== Errors
206
230
  # ArgumentError:: Raised if you supply a required argument after a non required one.
207
231
  #
208
- def argument(name, options = {}) # rubocop:disable MethodLength
232
+ def argument(name, options = {})
209
233
  is_thor_reserved_word?(name, :argument)
210
234
  no_commands { attr_accessor name }
211
235
 
@@ -219,11 +243,13 @@ class Bundler::Thor
219
243
 
220
244
  remove_argument name
221
245
 
222
- arguments.each do |argument|
223
- next if argument.required?
224
- fail ArgumentError, "You cannot have #{name.to_s.inspect} as required argument after " <<
225
- "the non-required argument #{argument.human_name.inspect}."
226
- end if required
246
+ if required
247
+ arguments.each do |argument|
248
+ next if argument.required?
249
+ raise ArgumentError, "You cannot have #{name.to_s.inspect} as required argument after " \
250
+ "the non-required argument #{argument.human_name.inspect}."
251
+ end
252
+ end
227
253
 
228
254
  options[:required] = required
229
255
 
@@ -343,7 +369,7 @@ class Bundler::Thor
343
369
  #
344
370
  def all_commands
345
371
  @all_commands ||= from_superclass(:all_commands, Bundler::Thor::CoreExt::OrderedHash.new)
346
- @all_commands.merge(commands)
372
+ @all_commands.merge!(commands)
347
373
  end
348
374
  alias_method :all_tasks, :all_commands
349
375
 
@@ -467,20 +493,18 @@ class Bundler::Thor
467
493
  alias_method :public_task, :public_command
468
494
 
469
495
  def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc:
470
- if has_namespace
471
- fail UndefinedCommandError, "Could not find command #{command.inspect} in #{namespace.inspect} namespace."
472
- else
473
- fail UndefinedCommandError, "Could not find command #{command.inspect}."
474
- end
496
+ raise UndefinedCommandError, "Could not find command #{command.inspect} in #{namespace.inspect} namespace." if has_namespace
497
+ raise UndefinedCommandError, "Could not find command #{command.inspect}."
475
498
  end
476
499
  alias_method :handle_no_task_error, :handle_no_command_error
477
500
 
478
501
  def handle_argument_error(command, error, args, arity) #:nodoc:
479
- msg = "ERROR: \"#{basename} #{command.name}\" was called with "
502
+ name = [command.ancestor_name, command.name].compact.join(" ")
503
+ msg = "ERROR: \"#{basename} #{name}\" was called with ".dup
480
504
  msg << "no arguments" if args.empty?
481
505
  msg << "arguments " << args.inspect unless args.empty?
482
506
  msg << "\nUsage: #{banner(command).inspect}"
483
- fail InvocationError, msg
507
+ raise InvocationError, msg
484
508
  end
485
509
 
486
510
  protected
@@ -513,14 +537,13 @@ class Bundler::Thor
513
537
  padding = options.map { |o| o.aliases.size }.max.to_i * 4
514
538
 
515
539
  options.each do |option|
516
- unless option.hide
517
- item = [option.usage(padding)]
518
- item.push(option.description ? "# #{option.description}" : "")
540
+ next if option.hide
541
+ item = [option.usage(padding)]
542
+ item.push(option.description ? "# #{option.description}" : "")
519
543
 
520
- list << item
521
- list << ["", "# Default: #{option.default}"] if option.show_default?
522
- list << ["", "# Possible values: #{option.enum.join(', ')}"] if option.enum
523
- end
544
+ list << item
545
+ list << ["", "# Default: #{option.default}"] if option.show_default?
546
+ list << ["", "# Possible values: #{option.enum.join(', ')}"] if option.enum
524
547
  end
525
548
 
526
549
  shell.say(group_name ? "#{group_name} options:" : "Options:")
@@ -531,7 +554,7 @@ class Bundler::Thor
531
554
  # Raises an error if the word given is a Bundler::Thor reserved word.
532
555
  def is_thor_reserved_word?(word, type) #:nodoc:
533
556
  return false unless THOR_RESERVED_WORDS.include?(word.to_s)
534
- fail "#{word.inspect} is a Bundler::Thor reserved word and cannot be defined as #{type}"
557
+ raise "#{word.inspect} is a Bundler::Thor reserved word and cannot be defined as #{type}"
535
558
  end
536
559
 
537
560
  # Build an option and adds it to the given scope.
@@ -541,7 +564,7 @@ class Bundler::Thor
541
564
  # options<Hash>:: Described in both class_option and method_option.
542
565
  # scope<Hash>:: Options hash that is being built up
543
566
  def build_option(name, options, scope) #:nodoc:
544
- scope[name] = Bundler::Thor::Option.new(name, options)
567
+ scope[name] = Bundler::Thor::Option.new(name, options.merge(:check_default_type => check_default_type?))
545
568
  end
546
569
 
547
570
  # Receives a hash of options, parse them and add to the scope. This is a
@@ -566,7 +589,7 @@ class Bundler::Thor
566
589
  elsif command = all_commands[name.to_s] # rubocop:disable AssignmentInCondition
567
590
  commands[name.to_s] = command.clone
568
591
  else
569
- fail ArgumentError, "You supplied :for => #{name.inspect}, but the command #{name.inspect} could not be found."
592
+ raise ArgumentError, "You supplied :for => #{name.inspect}, but the command #{name.inspect} could not be found."
570
593
  end
571
594
  end
572
595
  alias_method :find_and_refresh_task, :find_and_refresh_command
@@ -649,7 +672,7 @@ class Bundler::Thor
649
672
 
650
673
  # SIGNATURE: The hook invoked by start.
651
674
  def dispatch(command, given_args, given_opts, config) #:nodoc:
652
- fail NotImplementedError
675
+ raise NotImplementedError
653
676
  end
654
677
  end
655
678
  end