bundler-prehistoric 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +100 -0
  5. data/CHANGELOG.md +1640 -0
  6. data/CONTRIBUTING.md +32 -0
  7. data/DEVELOPMENT.md +117 -0
  8. data/Gemfile +3 -0
  9. data/ISSUES.md +96 -0
  10. data/LICENSE.md +23 -0
  11. data/README.md +46 -0
  12. data/Rakefile +256 -0
  13. data/UPGRADING.md +103 -0
  14. data/bin/bundle +21 -0
  15. data/bin/bundle_ruby +56 -0
  16. data/bin/bundler +21 -0
  17. data/bundler.gemspec +33 -0
  18. data/lib/bundler.rb +442 -0
  19. data/lib/bundler/backports/time.rb +7 -0
  20. data/lib/bundler/capistrano.rb +16 -0
  21. data/lib/bundler/cli.rb +395 -0
  22. data/lib/bundler/cli/binstubs.rb +38 -0
  23. data/lib/bundler/cli/cache.rb +34 -0
  24. data/lib/bundler/cli/check.rb +35 -0
  25. data/lib/bundler/cli/clean.rb +19 -0
  26. data/lib/bundler/cli/common.rb +54 -0
  27. data/lib/bundler/cli/config.rb +84 -0
  28. data/lib/bundler/cli/console.rb +39 -0
  29. data/lib/bundler/cli/exec.rb +37 -0
  30. data/lib/bundler/cli/gem.rb +101 -0
  31. data/lib/bundler/cli/init.rb +33 -0
  32. data/lib/bundler/cli/inject.rb +33 -0
  33. data/lib/bundler/cli/install.rb +133 -0
  34. data/lib/bundler/cli/open.rb +23 -0
  35. data/lib/bundler/cli/outdated.rb +80 -0
  36. data/lib/bundler/cli/package.rb +36 -0
  37. data/lib/bundler/cli/platform.rb +43 -0
  38. data/lib/bundler/cli/show.rb +48 -0
  39. data/lib/bundler/cli/update.rb +73 -0
  40. data/lib/bundler/cli/viz.rb +27 -0
  41. data/lib/bundler/constants.rb +5 -0
  42. data/lib/bundler/current_ruby.rb +155 -0
  43. data/lib/bundler/definition.rb +604 -0
  44. data/lib/bundler/dep_proxy.rb +43 -0
  45. data/lib/bundler/dependency.rb +106 -0
  46. data/lib/bundler/deployment.rb +59 -0
  47. data/lib/bundler/deprecate.rb +15 -0
  48. data/lib/bundler/dsl.rb +305 -0
  49. data/lib/bundler/endpoint_specification.rb +76 -0
  50. data/lib/bundler/env.rb +56 -0
  51. data/lib/bundler/environment.rb +42 -0
  52. data/lib/bundler/fetcher.rb +396 -0
  53. data/lib/bundler/friendly_errors.rb +42 -0
  54. data/lib/bundler/gem_helper.rb +169 -0
  55. data/lib/bundler/gem_helpers.rb +25 -0
  56. data/lib/bundler/gem_installer.rb +9 -0
  57. data/lib/bundler/gem_path_manipulation.rb +8 -0
  58. data/lib/bundler/gem_tasks.rb +2 -0
  59. data/lib/bundler/graph.rb +169 -0
  60. data/lib/bundler/index.rb +184 -0
  61. data/lib/bundler/injector.rb +64 -0
  62. data/lib/bundler/installer.rb +332 -0
  63. data/lib/bundler/lazy_specification.rb +83 -0
  64. data/lib/bundler/lockfile_parser.rb +146 -0
  65. data/lib/bundler/match_platform.rb +13 -0
  66. data/lib/bundler/parallel_workers.rb +18 -0
  67. data/lib/bundler/parallel_workers/thread_worker.rb +30 -0
  68. data/lib/bundler/parallel_workers/unix_worker.rb +101 -0
  69. data/lib/bundler/parallel_workers/worker.rb +69 -0
  70. data/lib/bundler/psyched_yaml.rb +26 -0
  71. data/lib/bundler/remote_specification.rb +57 -0
  72. data/lib/bundler/resolver.rb +534 -0
  73. data/lib/bundler/retry.rb +60 -0
  74. data/lib/bundler/ruby_dsl.rb +11 -0
  75. data/lib/bundler/ruby_version.rb +117 -0
  76. data/lib/bundler/rubygems_ext.rb +171 -0
  77. data/lib/bundler/rubygems_integration.rb +578 -0
  78. data/lib/bundler/runtime.rb +310 -0
  79. data/lib/bundler/settings.rb +176 -0
  80. data/lib/bundler/setup.rb +23 -0
  81. data/lib/bundler/shared_helpers.rb +110 -0
  82. data/lib/bundler/similarity_detector.rb +63 -0
  83. data/lib/bundler/source.rb +29 -0
  84. data/lib/bundler/source/git.rb +289 -0
  85. data/lib/bundler/source/git/git_proxy.rb +158 -0
  86. data/lib/bundler/source/path.rb +225 -0
  87. data/lib/bundler/source/path/installer.rb +38 -0
  88. data/lib/bundler/source/rubygems.rb +334 -0
  89. data/lib/bundler/source/svn.rb +260 -0
  90. data/lib/bundler/source/svn/svn_proxy.rb +110 -0
  91. data/lib/bundler/spec_set.rb +154 -0
  92. data/lib/bundler/ssl_certs/.document +1 -0
  93. data/lib/bundler/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +14 -0
  94. data/lib/bundler/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +23 -0
  95. data/lib/bundler/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +28 -0
  96. data/lib/bundler/ssl_certs/GeoTrustGlobalCA.pem +20 -0
  97. data/lib/bundler/ssl_certs/certificate_manager.rb +41 -0
  98. data/lib/bundler/templates/Executable +16 -0
  99. data/lib/bundler/templates/Executable.standalone +12 -0
  100. data/lib/bundler/templates/Gemfile +4 -0
  101. data/lib/bundler/templates/newgem/.travis.yml.tt +3 -0
  102. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  103. data/lib/bundler/templates/newgem/LICENSE.txt.tt +22 -0
  104. data/lib/bundler/templates/newgem/README.md.tt +31 -0
  105. data/lib/bundler/templates/newgem/Rakefile.tt +26 -0
  106. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  107. data/lib/bundler/templates/newgem/consolerc.tt +3 -0
  108. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  109. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  110. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  111. data/lib/bundler/templates/newgem/gitignore.tt +16 -0
  112. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  113. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  114. data/lib/bundler/templates/newgem/newgem.gemspec.tt +38 -0
  115. data/lib/bundler/templates/newgem/rspec.tt +2 -0
  116. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  117. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  118. data/lib/bundler/templates/newgem/test/minitest_helper.rb.tt +4 -0
  119. data/lib/bundler/templates/newgem/test/test_newgem.rb.tt +11 -0
  120. data/lib/bundler/ui.rb +7 -0
  121. data/lib/bundler/ui/rg_proxy.rb +21 -0
  122. data/lib/bundler/ui/shell.rb +98 -0
  123. data/lib/bundler/ui/silent.rb +44 -0
  124. data/lib/bundler/vendor/.document +0 -0
  125. data/lib/bundler/vendor/net/http/faster.rb +26 -0
  126. data/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  127. data/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  128. data/lib/bundler/vendor/thor.rb +480 -0
  129. data/lib/bundler/vendor/thor/actions.rb +319 -0
  130. data/lib/bundler/vendor/thor/actions/create_file.rb +103 -0
  131. data/lib/bundler/vendor/thor/actions/create_link.rb +59 -0
  132. data/lib/bundler/vendor/thor/actions/directory.rb +118 -0
  133. data/lib/bundler/vendor/thor/actions/empty_directory.rb +135 -0
  134. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +316 -0
  135. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +107 -0
  136. data/lib/bundler/vendor/thor/base.rb +656 -0
  137. data/lib/bundler/vendor/thor/command.rb +133 -0
  138. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  139. data/lib/bundler/vendor/thor/core_ext/io_binary_read.rb +10 -0
  140. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +98 -0
  141. data/lib/bundler/vendor/thor/error.rb +32 -0
  142. data/lib/bundler/vendor/thor/group.rb +281 -0
  143. data/lib/bundler/vendor/thor/invocation.rb +173 -0
  144. data/lib/bundler/vendor/thor/line_editor.rb +17 -0
  145. data/lib/bundler/vendor/thor/line_editor/basic.rb +35 -0
  146. data/lib/bundler/vendor/thor/line_editor/readline.rb +88 -0
  147. data/lib/bundler/vendor/thor/parser.rb +4 -0
  148. data/lib/bundler/vendor/thor/parser/argument.rb +73 -0
  149. data/lib/bundler/vendor/thor/parser/arguments.rb +175 -0
  150. data/lib/bundler/vendor/thor/parser/option.rb +121 -0
  151. data/lib/bundler/vendor/thor/parser/options.rb +218 -0
  152. data/lib/bundler/vendor/thor/rake_compat.rb +71 -0
  153. data/lib/bundler/vendor/thor/runner.rb +322 -0
  154. data/lib/bundler/vendor/thor/shell.rb +81 -0
  155. data/lib/bundler/vendor/thor/shell/basic.rb +420 -0
  156. data/lib/bundler/vendor/thor/shell/color.rb +149 -0
  157. data/lib/bundler/vendor/thor/shell/html.rb +126 -0
  158. data/lib/bundler/vendor/thor/util.rb +267 -0
  159. data/lib/bundler/vendor/thor/version.rb +3 -0
  160. data/lib/bundler/vendored_persistent.rb +3 -0
  161. data/lib/bundler/vendored_thor.rb +8 -0
  162. data/lib/bundler/version.rb +6 -0
  163. data/lib/bundler/vlad.rb +11 -0
  164. data/man/bundle-config.ronn +155 -0
  165. data/man/bundle-exec.ronn +136 -0
  166. data/man/bundle-install.ronn +372 -0
  167. data/man/bundle-package.ronn +59 -0
  168. data/man/bundle-platform.ronn +42 -0
  169. data/man/bundle-update.ronn +179 -0
  170. data/man/bundle.ronn +92 -0
  171. data/man/gemfile.5.ronn +369 -0
  172. data/man/index.txt +7 -0
  173. data/spec/bundler/bundler_spec.rb +74 -0
  174. data/spec/bundler/cli_spec.rb +16 -0
  175. data/spec/bundler/definition_spec.rb +21 -0
  176. data/spec/bundler/dsl_spec.rb +108 -0
  177. data/spec/bundler/friendly_errors_spec.rb +13 -0
  178. data/spec/bundler/gem_helper_spec.rb +225 -0
  179. data/spec/bundler/psyched_yaml_spec.rb +8 -0
  180. data/spec/bundler/retry_spec.rb +59 -0
  181. data/spec/bundler/settings_spec.rb +13 -0
  182. data/spec/bundler/source_spec.rb +25 -0
  183. data/spec/cache/gems_spec.rb +316 -0
  184. data/spec/cache/git_spec.rb +188 -0
  185. data/spec/cache/path_spec.rb +121 -0
  186. data/spec/cache/platform_spec.rb +53 -0
  187. data/spec/cache/svn_spec.rb +82 -0
  188. data/spec/commands/binstubs_spec.rb +246 -0
  189. data/spec/commands/check_spec.rb +278 -0
  190. data/spec/commands/clean_spec.rb +652 -0
  191. data/spec/commands/config_spec.rb +227 -0
  192. data/spec/commands/console_spec.rb +102 -0
  193. data/spec/commands/exec_spec.rb +367 -0
  194. data/spec/commands/help_spec.rb +39 -0
  195. data/spec/commands/init_spec.rb +39 -0
  196. data/spec/commands/inject_spec.rb +78 -0
  197. data/spec/commands/licenses_spec.rb +31 -0
  198. data/spec/commands/newgem_spec.rb +451 -0
  199. data/spec/commands/open_spec.rb +80 -0
  200. data/spec/commands/outdated_spec.rb +168 -0
  201. data/spec/commands/package_spec.rb +128 -0
  202. data/spec/commands/show_spec.rb +152 -0
  203. data/spec/install/binstubs_spec.rb +24 -0
  204. data/spec/install/bundler_spec.rb +146 -0
  205. data/spec/install/deploy_spec.rb +237 -0
  206. data/spec/install/gemfile/gemspec_spec.rb +170 -0
  207. data/spec/install/gemfile/git_spec.rb +967 -0
  208. data/spec/install/gemfile/path_spec.rb +480 -0
  209. data/spec/install/gemfile/svn_spec.rb +582 -0
  210. data/spec/install/gemfile_spec.rb +44 -0
  211. data/spec/install/gems/c_ext_spec.rb +48 -0
  212. data/spec/install/gems/dependency_api_spec.rb +580 -0
  213. data/spec/install/gems/env_spec.rb +107 -0
  214. data/spec/install/gems/flex_spec.rb +314 -0
  215. data/spec/install/gems/groups_spec.rb +308 -0
  216. data/spec/install/gems/mirror_spec.rb +39 -0
  217. data/spec/install/gems/platform_spec.rb +221 -0
  218. data/spec/install/gems/post_install_spec.rb +121 -0
  219. data/spec/install/gems/resolving_spec.rb +124 -0
  220. data/spec/install/gems/simple_case_spec.rb +386 -0
  221. data/spec/install/gems/standalone_spec.rb +260 -0
  222. data/spec/install/gems/sudo_spec.rb +136 -0
  223. data/spec/install/gems/win32_spec.rb +26 -0
  224. data/spec/install/gemspecs_spec.rb +50 -0
  225. data/spec/install/path_spec.rb +150 -0
  226. data/spec/install/post_bundle_message_spec.rb +142 -0
  227. data/spec/install/prereleases_spec.rb +43 -0
  228. data/spec/install/security_policy_spec.rb +77 -0
  229. data/spec/install/upgrade_spec.rb +26 -0
  230. data/spec/lock/git_spec.rb +34 -0
  231. data/spec/lock/lockfile_spec.rb +912 -0
  232. data/spec/lock/svn_spec.rb +35 -0
  233. data/spec/other/bundle_ruby_spec.rb +142 -0
  234. data/spec/other/cli_dispatch_spec.rb +21 -0
  235. data/spec/other/ext_spec.rb +60 -0
  236. data/spec/other/platform_spec.rb +1285 -0
  237. data/spec/other/ssl_cert_spec.rb +10 -0
  238. data/spec/quality_spec.rb +88 -0
  239. data/spec/realworld/dependency_api_spec.rb +60 -0
  240. data/spec/realworld/edgecases_spec.rb +177 -0
  241. data/spec/realworld/parallel_spec.rb +69 -0
  242. data/spec/resolver/basic_spec.rb +66 -0
  243. data/spec/resolver/platform_spec.rb +88 -0
  244. data/spec/runtime/executable_spec.rb +149 -0
  245. data/spec/runtime/load_spec.rb +107 -0
  246. data/spec/runtime/platform_spec.rb +90 -0
  247. data/spec/runtime/require_spec.rb +332 -0
  248. data/spec/runtime/setup_spec.rb +856 -0
  249. data/spec/runtime/with_clean_env_spec.rb +91 -0
  250. data/spec/spec_helper.rb +114 -0
  251. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  252. data/spec/support/artifice/endpoint.rb +71 -0
  253. data/spec/support/artifice/endpoint_500.rb +37 -0
  254. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  255. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  256. data/spec/support/artifice/endpoint_creds_diff_host.rb +38 -0
  257. data/spec/support/artifice/endpoint_extra.rb +31 -0
  258. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  259. data/spec/support/artifice/endpoint_fallback.rb +17 -0
  260. data/spec/support/artifice/endpoint_host_redirect.rb +15 -0
  261. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  262. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  263. data/spec/support/artifice/endpoint_strict_basic_authentication.rb +18 -0
  264. data/spec/support/artifice/endpoint_timeout.rb +13 -0
  265. data/spec/support/builders.rb +748 -0
  266. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  267. data/spec/support/fakeweb/windows.rb +23 -0
  268. data/spec/support/hax.rb +22 -0
  269. data/spec/support/helpers.rb +348 -0
  270. data/spec/support/indexes.rb +280 -0
  271. data/spec/support/less_than_proc.rb +14 -0
  272. data/spec/support/matchers.rb +77 -0
  273. data/spec/support/path.rb +81 -0
  274. data/spec/support/permissions.rb +10 -0
  275. data/spec/support/platforms.rb +94 -0
  276. data/spec/support/ruby_ext.rb +20 -0
  277. data/spec/support/rubygems_ext.rb +39 -0
  278. data/spec/support/streams.rb +13 -0
  279. data/spec/support/sudo.rb +16 -0
  280. data/spec/update/gems_spec.rb +201 -0
  281. data/spec/update/git_spec.rb +236 -0
  282. data/spec/update/source_spec.rb +63 -0
  283. data/spec/update/svn_spec.rb +100 -0
  284. metadata +486 -0
@@ -0,0 +1,118 @@
1
+ require 'thor/actions/empty_directory'
2
+
3
+ class Thor
4
+ module Actions
5
+ # Copies recursively the files from source directory to root directory.
6
+ # If any of the files finishes with .tt, it's considered to be a template
7
+ # and is placed in the destination without the extension .tt. If any
8
+ # empty directory is found, it's copied and all .empty_directory files are
9
+ # ignored. If any file name is wrapped within % signs, the text within
10
+ # the % signs will be executed as a method and replaced with the returned
11
+ # value. Let's suppose a doc directory with the following files:
12
+ #
13
+ # doc/
14
+ # components/.empty_directory
15
+ # README
16
+ # rdoc.rb.tt
17
+ # %app_name%.rb
18
+ #
19
+ # When invoked as:
20
+ #
21
+ # directory "doc"
22
+ #
23
+ # It will create a doc directory in the destination with the following
24
+ # files (assuming that the `app_name` method returns the value "blog"):
25
+ #
26
+ # doc/
27
+ # components/
28
+ # README
29
+ # rdoc.rb
30
+ # blog.rb
31
+ #
32
+ # <b>Encoded path note:</b> Since Thor internals use Object#respond_to? to check if it can
33
+ # expand %something%, this `something` should be a public method in the class calling
34
+ # #directory. If a method is private, Thor stack raises PrivateMethodEncodedError.
35
+ #
36
+ # ==== Parameters
37
+ # source<String>:: the relative path to the source root.
38
+ # destination<String>:: the relative path to the destination root.
39
+ # config<Hash>:: give :verbose => false to not log the status.
40
+ # If :recursive => false, does not look for paths recursively.
41
+ # If :mode => :preserve, preserve the file mode from the source.
42
+ # If :exclude_pattern => /regexp/, prevents copying files that match that regexp.
43
+ #
44
+ # ==== Examples
45
+ #
46
+ # directory "doc"
47
+ # directory "doc", "docs", :recursive => false
48
+ #
49
+ def directory(source, *args, &block)
50
+ config = args.last.is_a?(Hash) ? args.pop : {}
51
+ destination = args.first || source
52
+ action Directory.new(self, source, destination || source, config, &block)
53
+ end
54
+
55
+ class Directory < EmptyDirectory #:nodoc:
56
+ attr_reader :source
57
+
58
+ def initialize(base, source, destination = nil, config = {}, &block)
59
+ @source = File.expand_path(base.find_in_source_paths(source.to_s))
60
+ @block = block
61
+ super(base, destination, {:recursive => true}.merge(config))
62
+ end
63
+
64
+ def invoke!
65
+ base.empty_directory given_destination, config
66
+ execute!
67
+ end
68
+
69
+ def revoke!
70
+ execute!
71
+ end
72
+
73
+ protected
74
+
75
+ def execute! # rubocop:disable MethodLength
76
+ lookup = Util.escape_globs(source)
77
+ lookup = config[:recursive] ? File.join(lookup, '**') : lookup
78
+ lookup = file_level_lookup(lookup)
79
+
80
+ files(lookup).sort.each do |file_source|
81
+ next if File.directory?(file_source)
82
+ next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern])
83
+ file_destination = File.join(given_destination, file_source.gsub(source, '.'))
84
+ file_destination.gsub!('/./', '/')
85
+
86
+ case file_source
87
+ when /\.empty_directory$/
88
+ dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
89
+ next if dirname == given_destination
90
+ base.empty_directory(dirname, config)
91
+ when /#{TEMPLATE_EXTNAME}$/
92
+ base.template(file_source, file_destination[0..-4], config, &@block)
93
+ else
94
+ base.copy_file(file_source, file_destination, config, &@block)
95
+ end
96
+ end
97
+ end
98
+
99
+ if RUBY_VERSION < '2.0'
100
+ def file_level_lookup(previous_lookup)
101
+ File.join(previous_lookup, '{*,.[a-z]*}')
102
+ end
103
+
104
+ def files(lookup)
105
+ Dir[lookup]
106
+ end
107
+ else
108
+ def file_level_lookup(previous_lookup)
109
+ File.join(previous_lookup, '*')
110
+ end
111
+
112
+ def files(lookup)
113
+ Dir.glob(lookup, File::FNM_DOTMATCH)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,135 @@
1
+ class Thor
2
+ module Actions
3
+ # Creates an empty directory.
4
+ #
5
+ # ==== Parameters
6
+ # destination<String>:: the relative path to the destination root.
7
+ # config<Hash>:: give :verbose => false to not log the status.
8
+ #
9
+ # ==== Examples
10
+ #
11
+ # empty_directory "doc"
12
+ #
13
+ def empty_directory(destination, config = {})
14
+ action EmptyDirectory.new(self, destination, config)
15
+ end
16
+
17
+ # Class which holds create directory logic. This is the base class for
18
+ # other actions like create_file and directory.
19
+ #
20
+ # This implementation is based in Templater actions, created by Jonas Nicklas
21
+ # and Michael S. Klishin under MIT LICENSE.
22
+ #
23
+ class EmptyDirectory #:nodoc:
24
+ attr_reader :base, :destination, :given_destination, :relative_destination, :config
25
+
26
+ # Initializes given the source and destination.
27
+ #
28
+ # ==== Parameters
29
+ # base<Thor::Base>:: A Thor::Base instance
30
+ # source<String>:: Relative path to the source of this file
31
+ # destination<String>:: Relative path to the destination of this file
32
+ # config<Hash>:: give :verbose => false to not log the status.
33
+ #
34
+ def initialize(base, destination, config = {})
35
+ @base, @config = base, {:verbose => true}.merge(config)
36
+ self.destination = destination
37
+ end
38
+
39
+ # Checks if the destination file already exists.
40
+ #
41
+ # ==== Returns
42
+ # Boolean:: true if the file exists, false otherwise.
43
+ #
44
+ def exists?
45
+ ::File.exist?(destination)
46
+ end
47
+
48
+ def invoke!
49
+ invoke_with_conflict_check do
50
+ ::FileUtils.mkdir_p(destination)
51
+ end
52
+ end
53
+
54
+ def revoke!
55
+ say_status :remove, :red
56
+ ::FileUtils.rm_rf(destination) if !pretend? && exists?
57
+ given_destination
58
+ end
59
+
60
+ protected
61
+
62
+ # Shortcut for pretend.
63
+ #
64
+ def pretend?
65
+ base.options[:pretend]
66
+ end
67
+
68
+ # Sets the absolute destination value from a relative destination value.
69
+ # It also stores the given and relative destination. Let's suppose our
70
+ # script is being executed on "dest", it sets the destination root to
71
+ # "dest". The destination, given_destination and relative_destination
72
+ # are related in the following way:
73
+ #
74
+ # inside "bar" do
75
+ # empty_directory "baz"
76
+ # end
77
+ #
78
+ # destination #=> dest/bar/baz
79
+ # relative_destination #=> bar/baz
80
+ # given_destination #=> baz
81
+ #
82
+ 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
88
+ end
89
+
90
+ # Filenames in the encoded form are converted. If you have a file:
91
+ #
92
+ # %file_name%.rb
93
+ #
94
+ # It calls #file_name from the base and replaces %-string with the
95
+ # return value (should be String) of #file_name:
96
+ #
97
+ # user.rb
98
+ #
99
+ # The method referenced can be either public or private.
100
+ #
101
+ def convert_encoded_instructions(filename)
102
+ filename.gsub(/%(.*?)%/) do |initial_string|
103
+ method = $1.strip
104
+ base.respond_to?(method, true) ? base.send(method) : initial_string
105
+ end
106
+ end
107
+
108
+ # Receives a hash of options and just execute the block if some
109
+ # conditions are met.
110
+ #
111
+ def invoke_with_conflict_check(&block)
112
+ if exists?
113
+ on_conflict_behavior(&block)
114
+ else
115
+ say_status :create, :green
116
+ block.call unless pretend?
117
+ end
118
+
119
+ destination
120
+ end
121
+
122
+ # What to do when the destination file already exists.
123
+ #
124
+ def on_conflict_behavior(&block)
125
+ say_status :exist, :blue
126
+ end
127
+
128
+ # Shortcut to say_status shell method.
129
+ #
130
+ def say_status(status, color)
131
+ base.shell.say_status status, relative_destination, color if config[:verbose]
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,316 @@
1
+ require 'erb'
2
+ require 'open-uri'
3
+
4
+ class Thor
5
+ module Actions
6
+ # Copies the file from the relative source to the relative destination. If
7
+ # the destination is not given it's assumed to be equal to the source.
8
+ #
9
+ # ==== Parameters
10
+ # source<String>:: the relative path to the source root.
11
+ # destination<String>:: the relative path to the destination root.
12
+ # config<Hash>:: give :verbose => false to not log the status, and
13
+ # :mode => :preserve, to preserve the file mode from the source.
14
+
15
+ #
16
+ # ==== Examples
17
+ #
18
+ # copy_file "README", "doc/README"
19
+ #
20
+ # copy_file "doc/README"
21
+ #
22
+ def copy_file(source, *args, &block)
23
+ config = args.last.is_a?(Hash) ? args.pop : {}
24
+ destination = args.first || source
25
+ source = File.expand_path(find_in_source_paths(source.to_s))
26
+
27
+ create_file destination, nil, config do
28
+ content = File.binread(source)
29
+ content = block.call(content) if block
30
+ content
31
+ end
32
+ if config[:mode] == :preserve
33
+ mode = File.stat(source).mode
34
+ chmod(destination, mode, config)
35
+ end
36
+ end
37
+
38
+ # Links the file from the relative source to the relative destination. If
39
+ # the destination is not given it's assumed to be equal to the source.
40
+ #
41
+ # ==== Parameters
42
+ # source<String>:: the relative path to the source root.
43
+ # destination<String>:: the relative path to the destination root.
44
+ # config<Hash>:: give :verbose => false to not log the status.
45
+ #
46
+ # ==== Examples
47
+ #
48
+ # link_file "README", "doc/README"
49
+ #
50
+ # link_file "doc/README"
51
+ #
52
+ def link_file(source, *args, &block)
53
+ config = args.last.is_a?(Hash) ? args.pop : {}
54
+ destination = args.first || source
55
+ source = File.expand_path(find_in_source_paths(source.to_s))
56
+
57
+ create_link destination, source, config
58
+ end
59
+
60
+ # Gets the content at the given address and places it at the given relative
61
+ # destination. If a block is given instead of destination, the content of
62
+ # the url is yielded and used as location.
63
+ #
64
+ # ==== Parameters
65
+ # source<String>:: the address of the given content.
66
+ # destination<String>:: the relative path to the destination root.
67
+ # config<Hash>:: give :verbose => false to not log the status.
68
+ #
69
+ # ==== Examples
70
+ #
71
+ # get "http://gist.github.com/103208", "doc/README"
72
+ #
73
+ # get "http://gist.github.com/103208" do |content|
74
+ # content.split("\n").first
75
+ # end
76
+ #
77
+ def get(source, *args, &block)
78
+ config = args.last.is_a?(Hash) ? args.pop : {}
79
+ destination = args.first
80
+
81
+ source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ %r{^https?\://}
82
+ render = open(source) { |input| input.binmode.read }
83
+
84
+ destination ||= if block_given?
85
+ block.arity == 1 ? block.call(render) : block.call
86
+ else
87
+ File.basename(source)
88
+ end
89
+
90
+ create_file destination, render, config
91
+ end
92
+
93
+ # Gets an ERB template at the relative source, executes it and makes a copy
94
+ # at the relative destination. If the destination is not given it's assumed
95
+ # to be equal to the source removing .tt from the filename.
96
+ #
97
+ # ==== Parameters
98
+ # source<String>:: the relative path to the source root.
99
+ # destination<String>:: the relative path to the destination root.
100
+ # config<Hash>:: give :verbose => false to not log the status.
101
+ #
102
+ # ==== Examples
103
+ #
104
+ # template "README", "doc/README"
105
+ #
106
+ # template "doc/README"
107
+ #
108
+ def template(source, *args, &block)
109
+ config = args.last.is_a?(Hash) ? args.pop : {}
110
+ destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/, '')
111
+
112
+ source = File.expand_path(find_in_source_paths(source.to_s))
113
+ context = instance_eval('binding')
114
+
115
+ 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
118
+ content
119
+ end
120
+ end
121
+
122
+ # Changes the mode of the given file or directory.
123
+ #
124
+ # ==== Parameters
125
+ # mode<Integer>:: the file mode
126
+ # path<String>:: the name of the file to change mode
127
+ # config<Hash>:: give :verbose => false to not log the status.
128
+ #
129
+ # ==== Example
130
+ #
131
+ # chmod "script/server", 0755
132
+ #
133
+ def chmod(path, mode, config = {})
134
+ return unless behavior == :invoke
135
+ path = File.expand_path(path, destination_root)
136
+ say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
137
+ FileUtils.chmod_R(mode, path) unless options[:pretend]
138
+ end
139
+
140
+ # Prepend text to a file. Since it depends on insert_into_file, it's reversible.
141
+ #
142
+ # ==== Parameters
143
+ # path<String>:: path of the file to be changed
144
+ # data<String>:: the data to prepend to the file, can be also given as a block.
145
+ # config<Hash>:: give :verbose => false to not log the status.
146
+ #
147
+ # ==== Example
148
+ #
149
+ # prepend_to_file 'config/environments/test.rb', 'config.gem "rspec"'
150
+ #
151
+ # prepend_to_file 'config/environments/test.rb' do
152
+ # 'config.gem "rspec"'
153
+ # end
154
+ #
155
+ def prepend_to_file(path, *args, &block)
156
+ config = args.last.is_a?(Hash) ? args.pop : {}
157
+ config.merge!(:after => /\A/)
158
+ insert_into_file(path, *(args << config), &block)
159
+ end
160
+ alias_method :prepend_file, :prepend_to_file
161
+
162
+ # Append text to a file. Since it depends on insert_into_file, it's reversible.
163
+ #
164
+ # ==== Parameters
165
+ # path<String>:: path of the file to be changed
166
+ # data<String>:: the data to append to the file, can be also given as a block.
167
+ # config<Hash>:: give :verbose => false to not log the status.
168
+ #
169
+ # ==== Example
170
+ #
171
+ # append_to_file 'config/environments/test.rb', 'config.gem "rspec"'
172
+ #
173
+ # append_to_file 'config/environments/test.rb' do
174
+ # 'config.gem "rspec"'
175
+ # end
176
+ #
177
+ def append_to_file(path, *args, &block)
178
+ config = args.last.is_a?(Hash) ? args.pop : {}
179
+ config.merge!(:before => /\z/)
180
+ insert_into_file(path, *(args << config), &block)
181
+ end
182
+ alias_method :append_file, :append_to_file
183
+
184
+ # Injects text right after the class definition. Since it depends on
185
+ # insert_into_file, it's reversible.
186
+ #
187
+ # ==== Parameters
188
+ # path<String>:: path of the file to be changed
189
+ # klass<String|Class>:: the class to be manipulated
190
+ # data<String>:: the data to append to the class, can be also given as a block.
191
+ # config<Hash>:: give :verbose => false to not log the status.
192
+ #
193
+ # ==== Examples
194
+ #
195
+ # inject_into_class "app/controllers/application_controller.rb", ApplicationController, " filter_parameter :password\n"
196
+ #
197
+ # inject_into_class "app/controllers/application_controller.rb", ApplicationController do
198
+ # " filter_parameter :password\n"
199
+ # end
200
+ #
201
+ def inject_into_class(path, klass, *args, &block)
202
+ config = args.last.is_a?(Hash) ? args.pop : {}
203
+ config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/)
204
+ insert_into_file(path, *(args << config), &block)
205
+ end
206
+
207
+ # Run a regular expression replacement on a file.
208
+ #
209
+ # ==== Parameters
210
+ # path<String>:: path of the file to be changed
211
+ # flag<Regexp|String>:: the regexp or string to be replaced
212
+ # replacement<String>:: the replacement, can be also given as a block
213
+ # config<Hash>:: give :verbose => false to not log the status.
214
+ #
215
+ # ==== Example
216
+ #
217
+ # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
218
+ #
219
+ # gsub_file 'README', /rake/, :green do |match|
220
+ # match << " no more. Use thor!"
221
+ # end
222
+ #
223
+ def gsub_file(path, flag, *args, &block)
224
+ return unless behavior == :invoke
225
+ config = args.last.is_a?(Hash) ? args.pop : {}
226
+
227
+ path = File.expand_path(path, destination_root)
228
+ say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
229
+
230
+ unless options[:pretend]
231
+ content = File.binread(path)
232
+ content.gsub!(flag, *args, &block)
233
+ File.open(path, 'wb') { |file| file.write(content) }
234
+ end
235
+ end
236
+
237
+ # Uncomment all lines matching a given regex. It will leave the space
238
+ # which existed before the comment hash in tact but will remove any spacing
239
+ # between the comment hash and the beginning of the line.
240
+ #
241
+ # ==== Parameters
242
+ # path<String>:: path of the file to be changed
243
+ # flag<Regexp|String>:: the regexp or string used to decide which lines to uncomment
244
+ # config<Hash>:: give :verbose => false to not log the status.
245
+ #
246
+ # ==== Example
247
+ #
248
+ # uncomment_lines 'config/initializers/session_store.rb', /active_record/
249
+ #
250
+ def uncomment_lines(path, flag, *args)
251
+ flag = flag.respond_to?(:source) ? flag.source : flag
252
+
253
+ gsub_file(path, /^(\s*)#[[:blank:]]*(.*#{flag})/, '\1\2', *args)
254
+ end
255
+
256
+ # Comment all lines matching a given regex. It will leave the space
257
+ # which existed before the beginning of the line in tact and will insert
258
+ # a single space after the comment hash.
259
+ #
260
+ # ==== Parameters
261
+ # path<String>:: path of the file to be changed
262
+ # flag<Regexp|String>:: the regexp or string used to decide which lines to comment
263
+ # config<Hash>:: give :verbose => false to not log the status.
264
+ #
265
+ # ==== Example
266
+ #
267
+ # comment_lines 'config/initializers/session_store.rb', /cookie_store/
268
+ #
269
+ def comment_lines(path, flag, *args)
270
+ flag = flag.respond_to?(:source) ? flag.source : flag
271
+
272
+ gsub_file(path, /^(\s*)([^#|\n]*#{flag})/, '\1# \2', *args)
273
+ end
274
+
275
+ # Removes a file at the given location.
276
+ #
277
+ # ==== Parameters
278
+ # path<String>:: path of the file to be changed
279
+ # config<Hash>:: give :verbose => false to not log the status.
280
+ #
281
+ # ==== Example
282
+ #
283
+ # remove_file 'README'
284
+ # remove_file 'app/controllers/application_controller.rb'
285
+ #
286
+ def remove_file(path, config = {})
287
+ return unless behavior == :invoke
288
+ path = File.expand_path(path, destination_root)
289
+
290
+ say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
291
+ ::FileUtils.rm_rf(path) if !options[:pretend] && File.exist?(path)
292
+ end
293
+ alias_method :remove_dir, :remove_file
294
+
295
+ attr_accessor :output_buffer
296
+ private :output_buffer, :output_buffer=
297
+
298
+ private
299
+
300
+ def concat(string)
301
+ @output_buffer.concat(string)
302
+ end
303
+
304
+ def capture(*args, &block)
305
+ with_output_buffer { block.call(*args) }
306
+ end
307
+
308
+ def with_output_buffer(buf = '') #:nodoc:
309
+ self.output_buffer, old_buffer = buf, output_buffer
310
+ yield
311
+ output_buffer
312
+ ensure
313
+ self.output_buffer = old_buffer
314
+ end
315
+ end
316
+ end