bundler_package_git 1.1.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. data/.gitignore +22 -0
  2. data/.rvmrc +1 -0
  3. data/CHANGELOG.md +659 -0
  4. data/ISSUES.md +47 -0
  5. data/LICENSE +23 -0
  6. data/README.md +29 -0
  7. data/Rakefile +167 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +22 -0
  10. data/bundler.gemspec +30 -0
  11. data/lib/bundler.rb +283 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +490 -0
  14. data/lib/bundler/definition.rb +429 -0
  15. data/lib/bundler/dependency.rb +130 -0
  16. data/lib/bundler/deployment.rb +53 -0
  17. data/lib/bundler/dsl.rb +243 -0
  18. data/lib/bundler/environment.rb +47 -0
  19. data/lib/bundler/fetcher.rb +101 -0
  20. data/lib/bundler/gem_helper.rb +146 -0
  21. data/lib/bundler/graph.rb +130 -0
  22. data/lib/bundler/index.rb +131 -0
  23. data/lib/bundler/installer.rb +117 -0
  24. data/lib/bundler/lazy_specification.rb +71 -0
  25. data/lib/bundler/lockfile_parser.rb +108 -0
  26. data/lib/bundler/remote_specification.rb +57 -0
  27. data/lib/bundler/resolver.rb +470 -0
  28. data/lib/bundler/rubygems_ext.rb +226 -0
  29. data/lib/bundler/runtime.rb +201 -0
  30. data/lib/bundler/settings.rb +117 -0
  31. data/lib/bundler/setup.rb +16 -0
  32. data/lib/bundler/shared_helpers.rb +167 -0
  33. data/lib/bundler/source.rb +675 -0
  34. data/lib/bundler/spec_set.rb +134 -0
  35. data/lib/bundler/templates/Executable +16 -0
  36. data/lib/bundler/templates/Gemfile +4 -0
  37. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  38. data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
  39. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  40. data/lib/bundler/templates/newgem/gitignore.tt +4 -0
  41. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +7 -0
  42. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  43. data/lib/bundler/templates/newgem/newgem.gemspec.tt +21 -0
  44. data/lib/bundler/ui.rb +73 -0
  45. data/lib/bundler/vendor/net/http/faster.rb +27 -0
  46. data/lib/bundler/vendor/net/http/persistent.rb +464 -0
  47. data/lib/bundler/vendor/thor.rb +319 -0
  48. data/lib/bundler/vendor/thor/actions.rb +297 -0
  49. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  50. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  51. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  52. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +229 -0
  53. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +104 -0
  54. data/lib/bundler/vendor/thor/base.rb +556 -0
  55. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  56. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  57. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  58. data/lib/bundler/vendor/thor/error.rb +30 -0
  59. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  60. data/lib/bundler/vendor/thor/parser.rb +4 -0
  61. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  62. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  63. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  64. data/lib/bundler/vendor/thor/parser/options.rb +174 -0
  65. data/lib/bundler/vendor/thor/shell.rb +88 -0
  66. data/lib/bundler/vendor/thor/shell/basic.rb +275 -0
  67. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  68. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  69. data/lib/bundler/vendor/thor/task.rb +114 -0
  70. data/lib/bundler/vendor/thor/util.rb +229 -0
  71. data/lib/bundler/vendor/thor/version.rb +3 -0
  72. data/lib/bundler/version.rb +6 -0
  73. data/lib/bundler/vlad.rb +9 -0
  74. data/man/bundle-config.ronn +90 -0
  75. data/man/bundle-exec.ronn +111 -0
  76. data/man/bundle-install.ronn +314 -0
  77. data/man/bundle-package.ronn +59 -0
  78. data/man/bundle-update.ronn +176 -0
  79. data/man/bundle.ronn +80 -0
  80. data/man/gemfile.5.ronn +279 -0
  81. data/man/index.txt +6 -0
  82. data/spec/cache/gems_spec.rb +219 -0
  83. data/spec/cache/git_spec.rb +9 -0
  84. data/spec/cache/path_spec.rb +27 -0
  85. data/spec/cache/platform_spec.rb +57 -0
  86. data/spec/install/deploy_spec.rb +197 -0
  87. data/spec/install/deprecated_spec.rb +37 -0
  88. data/spec/install/gems/c_ext_spec.rb +48 -0
  89. data/spec/install/gems/dependency_api_spec.rb +85 -0
  90. data/spec/install/gems/env_spec.rb +107 -0
  91. data/spec/install/gems/flex_spec.rb +313 -0
  92. data/spec/install/gems/groups_spec.rb +245 -0
  93. data/spec/install/gems/packed_spec.rb +84 -0
  94. data/spec/install/gems/platform_spec.rb +208 -0
  95. data/spec/install/gems/resolving_spec.rb +72 -0
  96. data/spec/install/gems/simple_case_spec.rb +715 -0
  97. data/spec/install/gems/standalone_spec.rb +162 -0
  98. data/spec/install/gems/sudo_spec.rb +73 -0
  99. data/spec/install/gems/win32_spec.rb +26 -0
  100. data/spec/install/gemspec_spec.rb +108 -0
  101. data/spec/install/git_spec.rb +571 -0
  102. data/spec/install/invalid_spec.rb +17 -0
  103. data/spec/install/path_spec.rb +353 -0
  104. data/spec/install/upgrade_spec.rb +26 -0
  105. data/spec/lock/git_spec.rb +35 -0
  106. data/spec/lock/lockfile_spec.rb +683 -0
  107. data/spec/other/check_spec.rb +221 -0
  108. data/spec/other/clean_spec.rb +202 -0
  109. data/spec/other/config_spec.rb +40 -0
  110. data/spec/other/console_spec.rb +54 -0
  111. data/spec/other/exec_spec.rb +241 -0
  112. data/spec/other/ext_spec.rb +16 -0
  113. data/spec/other/gem_helper_spec.rb +128 -0
  114. data/spec/other/help_spec.rb +38 -0
  115. data/spec/other/init_spec.rb +40 -0
  116. data/spec/other/newgem_spec.rb +24 -0
  117. data/spec/other/open_spec.rb +35 -0
  118. data/spec/other/show_spec.rb +82 -0
  119. data/spec/pack/gems_spec.rb +54 -0
  120. data/spec/quality_spec.rb +58 -0
  121. data/spec/resolver/basic_spec.rb +20 -0
  122. data/spec/resolver/platform_spec.rb +82 -0
  123. data/spec/runtime/executable_spec.rb +110 -0
  124. data/spec/runtime/load_spec.rb +107 -0
  125. data/spec/runtime/platform_spec.rb +90 -0
  126. data/spec/runtime/require_spec.rb +231 -0
  127. data/spec/runtime/setup_spec.rb +688 -0
  128. data/spec/runtime/with_clean_env_spec.rb +15 -0
  129. data/spec/spec_helper.rb +85 -0
  130. data/spec/support/artifice/endpoint.rb +50 -0
  131. data/spec/support/artifice/endpoint_fallback.rb +22 -0
  132. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  133. data/spec/support/artifice/endpoint_redirect.rb +11 -0
  134. data/spec/support/builders.rb +574 -0
  135. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  136. data/spec/support/fakeweb/windows.rb +23 -0
  137. data/spec/support/helpers.rb +246 -0
  138. data/spec/support/indexes.rb +112 -0
  139. data/spec/support/matchers.rb +89 -0
  140. data/spec/support/path.rb +73 -0
  141. data/spec/support/platforms.rb +53 -0
  142. data/spec/support/ruby_ext.rb +20 -0
  143. data/spec/support/rubygems_ext.rb +35 -0
  144. data/spec/support/rubygems_hax/platform.rb +11 -0
  145. data/spec/support/sudo.rb +21 -0
  146. data/spec/update/gems_spec.rb +121 -0
  147. data/spec/update/git_spec.rb +196 -0
  148. data/spec/update/source_spec.rb +51 -0
  149. metadata +294 -0
@@ -0,0 +1,105 @@
1
+ require 'thor/actions/empty_directory'
2
+
3
+ class Thor
4
+ module Actions
5
+
6
+ # Create a new file relative to the destination root with the given data,
7
+ # which is the return value of a block or a data string.
8
+ #
9
+ # ==== Parameters
10
+ # destination<String>:: the relative path to the destination root.
11
+ # data<String|NilClass>:: the data to append to the file.
12
+ # config<Hash>:: give :verbose => false to not log the status.
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # create_file "lib/fun_party.rb" do
17
+ # hostname = ask("What is the virtual hostname I should use?")
18
+ # "vhost.name = #{hostname}"
19
+ # end
20
+ #
21
+ # create_file "config/apach.conf", "your apache config"
22
+ #
23
+ def create_file(destination, *args, &block)
24
+ config = args.last.is_a?(Hash) ? args.pop : {}
25
+ data = args.first
26
+ action CreateFile.new(self, destination, block || data.to_s, config)
27
+ end
28
+ alias :add_file :create_file
29
+
30
+ # AddFile is a subset of Template, which instead of rendering a file with
31
+ # ERB, it gets the content from the user.
32
+ #
33
+ class CreateFile < EmptyDirectory #:nodoc:
34
+ attr_reader :data
35
+
36
+ def initialize(base, destination, data, config={})
37
+ @data = data
38
+ super(base, destination, config)
39
+ end
40
+
41
+ # Checks if the content of the file at the destination is identical to the rendered result.
42
+ #
43
+ # ==== Returns
44
+ # Boolean:: true if it is identical, false otherwise.
45
+ #
46
+ def identical?
47
+ exists? && File.binread(destination) == render
48
+ end
49
+
50
+ # Holds the content to be added to the file.
51
+ #
52
+ def render
53
+ @render ||= if data.is_a?(Proc)
54
+ data.call
55
+ else
56
+ data
57
+ end
58
+ end
59
+
60
+ def invoke!
61
+ invoke_with_conflict_check do
62
+ FileUtils.mkdir_p(File.dirname(destination))
63
+ File.open(destination, 'wb') { |f| f.write render }
64
+ end
65
+ given_destination
66
+ end
67
+
68
+ protected
69
+
70
+ # Now on conflict we check if the file is identical or not.
71
+ #
72
+ def on_conflict_behavior(&block)
73
+ if identical?
74
+ say_status :identical, :blue
75
+ else
76
+ options = base.options.merge(config)
77
+ force_or_skip_or_conflict(options[:force], options[:skip], &block)
78
+ end
79
+ end
80
+
81
+ # If force is true, run the action, otherwise check if it's not being
82
+ # skipped. If both are false, show the file_collision menu, if the menu
83
+ # returns true, force it, otherwise skip.
84
+ #
85
+ def force_or_skip_or_conflict(force, skip, &block)
86
+ if force
87
+ say_status :force, :yellow
88
+ block.call unless pretend?
89
+ elsif skip
90
+ say_status :skip, :yellow
91
+ else
92
+ say_status :conflict, :red
93
+ force_or_skip_or_conflict(force_on_collision?, true, &block)
94
+ end
95
+ end
96
+
97
+ # Shows the file collision menu to the user and gets the result.
98
+ #
99
+ def force_on_collision?
100
+ base.shell.file_collision(destination){ render }
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,93 @@
1
+ require 'thor/actions/empty_directory'
2
+
3
+ class Thor
4
+ module Actions
5
+
6
+ # Copies recursively the files from source directory to root directory.
7
+ # If any of the files finishes with .tt, it's considered to be a template
8
+ # and is placed in the destination without the extension .tt. If any
9
+ # empty directory is found, it's copied and all .empty_directory files are
10
+ # ignored. Remember that file paths can also be encoded, let's suppose a doc
11
+ # 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 is "blog"):
25
+ #
26
+ # doc/
27
+ # components/
28
+ # README
29
+ # rdoc.rb
30
+ # blog.rb
31
+ #
32
+ # ==== Parameters
33
+ # source<String>:: the relative path to the source root.
34
+ # destination<String>:: the relative path to the destination root.
35
+ # config<Hash>:: give :verbose => false to not log the status.
36
+ # If :recursive => false, does not look for paths recursively.
37
+ #
38
+ # ==== Examples
39
+ #
40
+ # directory "doc"
41
+ # directory "doc", "docs", :recursive => false
42
+ #
43
+ def directory(source, *args, &block)
44
+ config = args.last.is_a?(Hash) ? args.pop : {}
45
+ destination = args.first || source
46
+ action Directory.new(self, source, destination || source, config, &block)
47
+ end
48
+
49
+ class Directory < EmptyDirectory #:nodoc:
50
+ attr_reader :source
51
+
52
+ def initialize(base, source, destination=nil, config={}, &block)
53
+ @source = File.expand_path(base.find_in_source_paths(source.to_s))
54
+ @block = block
55
+ super(base, destination, { :recursive => true }.merge(config))
56
+ end
57
+
58
+ def invoke!
59
+ base.empty_directory given_destination, config
60
+ execute!
61
+ end
62
+
63
+ def revoke!
64
+ execute!
65
+ end
66
+
67
+ protected
68
+
69
+ def execute!
70
+ lookup = config[:recursive] ? File.join(source, '**') : source
71
+ lookup = File.join(lookup, '{*,.[a-z]*}')
72
+
73
+ Dir[lookup].each do |file_source|
74
+ next if File.directory?(file_source)
75
+ file_destination = File.join(given_destination, file_source.gsub(source, '.'))
76
+ file_destination.gsub!('/./', '/')
77
+
78
+ case file_source
79
+ when /\.empty_directory$/
80
+ dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
81
+ next if dirname == given_destination
82
+ base.empty_directory(dirname, config)
83
+ when /\.tt$/
84
+ destination = base.template(file_source, file_destination[0..-4], config, &@block)
85
+ else
86
+ destination = base.copy_file(file_source, file_destination, config, &@block)
87
+ end
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,134 @@
1
+ class Thor
2
+ module Actions
3
+
4
+ # Creates an empty directory.
5
+ #
6
+ # ==== Parameters
7
+ # destination<String>:: the relative path to the destination root.
8
+ # config<Hash>:: give :verbose => false to not log the status.
9
+ #
10
+ # ==== Examples
11
+ #
12
+ # empty_directory "doc"
13
+ #
14
+ def empty_directory(destination, config={})
15
+ action EmptyDirectory.new(self, destination, config)
16
+ end
17
+
18
+ # Class which holds create directory logic. This is the base class for
19
+ # other actions like create_file and directory.
20
+ #
21
+ # This implementation is based in Templater actions, created by Jonas Nicklas
22
+ # and Michael S. Klishin under MIT LICENSE.
23
+ #
24
+ class EmptyDirectory #:nodoc:
25
+ attr_reader :base, :destination, :given_destination, :relative_destination, :config
26
+
27
+ # Initializes given the source and destination.
28
+ #
29
+ # ==== Parameters
30
+ # base<Thor::Base>:: A Thor::Base instance
31
+ # source<String>:: Relative path to the source of this file
32
+ # destination<String>:: Relative path to the destination of this file
33
+ # config<Hash>:: give :verbose => false to not log the status.
34
+ #
35
+ def initialize(base, destination, config={})
36
+ @base, @config = base, { :verbose => true }.merge(config)
37
+ self.destination = destination
38
+ end
39
+
40
+ # Checks if the destination file already exists.
41
+ #
42
+ # ==== Returns
43
+ # Boolean:: true if the file exists, false otherwise.
44
+ #
45
+ def exists?
46
+ ::File.exists?(destination)
47
+ end
48
+
49
+ def invoke!
50
+ invoke_with_conflict_check do
51
+ ::FileUtils.mkdir_p(destination)
52
+ end
53
+ end
54
+
55
+ def revoke!
56
+ say_status :remove, :red
57
+ ::FileUtils.rm_rf(destination) if !pretend? && exists?
58
+ given_destination
59
+ end
60
+
61
+ protected
62
+
63
+ # Shortcut for pretend.
64
+ #
65
+ def pretend?
66
+ base.options[:pretend]
67
+ end
68
+
69
+ # Sets the absolute destination value from a relative destination value.
70
+ # It also stores the given and relative destination. Let's suppose our
71
+ # script is being executed on "dest", it sets the destination root to
72
+ # "dest". The destination, given_destination and relative_destination
73
+ # are related in the following way:
74
+ #
75
+ # inside "bar" do
76
+ # empty_directory "baz"
77
+ # end
78
+ #
79
+ # destination #=> dest/bar/baz
80
+ # relative_destination #=> bar/baz
81
+ # given_destination #=> baz
82
+ #
83
+ def destination=(destination)
84
+ if destination
85
+ @given_destination = convert_encoded_instructions(destination.to_s)
86
+ @destination = ::File.expand_path(@given_destination, base.destination_root)
87
+ @relative_destination = base.relative_to_original_destination_root(@destination)
88
+ end
89
+ end
90
+
91
+ # Filenames in the encoded form are converted. If you have a file:
92
+ #
93
+ # %class_name%.rb
94
+ #
95
+ # It gets the class name from the base and replace it:
96
+ #
97
+ # user.rb
98
+ #
99
+ def convert_encoded_instructions(filename)
100
+ filename.gsub(/%(.*?)%/) do |string|
101
+ instruction = $1.strip
102
+ base.respond_to?(instruction) ? base.send(instruction) : string
103
+ end
104
+ end
105
+
106
+ # Receives a hash of options and just execute the block if some
107
+ # conditions are met.
108
+ #
109
+ def invoke_with_conflict_check(&block)
110
+ if exists?
111
+ on_conflict_behavior(&block)
112
+ else
113
+ say_status :create, :green
114
+ block.call unless pretend?
115
+ end
116
+
117
+ destination
118
+ end
119
+
120
+ # What to do when the destination file already exists.
121
+ #
122
+ def on_conflict_behavior(&block)
123
+ say_status :exist, :blue
124
+ end
125
+
126
+ # Shortcut to say_status shell method.
127
+ #
128
+ def say_status(status, color)
129
+ base.shell.say_status status, relative_destination, color if config[:verbose]
130
+ end
131
+
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,229 @@
1
+ require 'erb'
2
+ require 'open-uri'
3
+
4
+ class Thor
5
+ module Actions
6
+
7
+ # Copies the file from the relative source to the relative destination. If
8
+ # the destination is not given it's assumed to be equal to the source.
9
+ #
10
+ # ==== Parameters
11
+ # source<String>:: the relative path to the source root.
12
+ # destination<String>:: the relative path to the destination root.
13
+ # config<Hash>:: give :verbose => false to not log the status.
14
+ #
15
+ # ==== Examples
16
+ #
17
+ # copy_file "README", "doc/README"
18
+ #
19
+ # copy_file "doc/README"
20
+ #
21
+ def copy_file(source, *args, &block)
22
+ config = args.last.is_a?(Hash) ? args.pop : {}
23
+ destination = args.first || source
24
+ source = File.expand_path(find_in_source_paths(source.to_s))
25
+
26
+ create_file destination, nil, config do
27
+ content = File.binread(source)
28
+ content = block.call(content) if block
29
+ content
30
+ end
31
+ end
32
+
33
+ # Gets the content at the given address and places it at the given relative
34
+ # destination. If a block is given instead of destination, the content of
35
+ # the url is yielded and used as location.
36
+ #
37
+ # ==== Parameters
38
+ # source<String>:: the address of the given content.
39
+ # destination<String>:: the relative path to the destination root.
40
+ # config<Hash>:: give :verbose => false to not log the status.
41
+ #
42
+ # ==== Examples
43
+ #
44
+ # get "http://gist.github.com/103208", "doc/README"
45
+ #
46
+ # get "http://gist.github.com/103208" do |content|
47
+ # content.split("\n").first
48
+ # end
49
+ #
50
+ def get(source, *args, &block)
51
+ config = args.last.is_a?(Hash) ? args.pop : {}
52
+ destination = args.first
53
+
54
+ source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^http\:\/\//
55
+ render = open(source) {|input| input.binmode.read }
56
+
57
+ destination ||= if block_given?
58
+ block.arity == 1 ? block.call(render) : block.call
59
+ else
60
+ File.basename(source)
61
+ end
62
+
63
+ create_file destination, render, config
64
+ end
65
+
66
+ # Gets an ERB template at the relative source, executes it and makes a copy
67
+ # at the relative destination. If the destination is not given it's assumed
68
+ # to be equal to the source removing .tt from the filename.
69
+ #
70
+ # ==== Parameters
71
+ # source<String>:: the relative path to the source root.
72
+ # destination<String>:: the relative path to the destination root.
73
+ # config<Hash>:: give :verbose => false to not log the status.
74
+ #
75
+ # ==== Examples
76
+ #
77
+ # template "README", "doc/README"
78
+ #
79
+ # template "doc/README"
80
+ #
81
+ def template(source, *args, &block)
82
+ config = args.last.is_a?(Hash) ? args.pop : {}
83
+ destination = args.first || source
84
+
85
+ source = File.expand_path(find_in_source_paths(source.to_s))
86
+ context = instance_eval('binding')
87
+
88
+ create_file destination, nil, config do
89
+ content = ERB.new(::File.binread(source), nil, '-').result(context)
90
+ content = block.call(content) if block
91
+ content
92
+ end
93
+ end
94
+
95
+ # Changes the mode of the given file or directory.
96
+ #
97
+ # ==== Parameters
98
+ # mode<Integer>:: the file mode
99
+ # path<String>:: the name of the file to change mode
100
+ # config<Hash>:: give :verbose => false to not log the status.
101
+ #
102
+ # ==== Example
103
+ #
104
+ # chmod "script/*", 0755
105
+ #
106
+ def chmod(path, mode, config={})
107
+ return unless behavior == :invoke
108
+ path = File.expand_path(path, destination_root)
109
+ say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
110
+ FileUtils.chmod_R(mode, path) unless options[:pretend]
111
+ end
112
+
113
+ # Prepend text to a file. Since it depends on inject_into_file, it's reversible.
114
+ #
115
+ # ==== Parameters
116
+ # path<String>:: path of the file to be changed
117
+ # data<String>:: the data to prepend to the file, can be also given as a block.
118
+ # config<Hash>:: give :verbose => false to not log the status.
119
+ #
120
+ # ==== Example
121
+ #
122
+ # prepend_file 'config/environments/test.rb', 'config.gem "rspec"'
123
+ #
124
+ # prepend_file 'config/environments/test.rb' do
125
+ # 'config.gem "rspec"'
126
+ # end
127
+ #
128
+ def prepend_file(path, *args, &block)
129
+ config = args.last.is_a?(Hash) ? args.pop : {}
130
+ config.merge!(:after => /\A/)
131
+ inject_into_file(path, *(args << config), &block)
132
+ end
133
+
134
+ # Append text to a file. Since it depends on inject_into_file, it's reversible.
135
+ #
136
+ # ==== Parameters
137
+ # path<String>:: path of the file to be changed
138
+ # data<String>:: the data to append to the file, can be also given as a block.
139
+ # config<Hash>:: give :verbose => false to not log the status.
140
+ #
141
+ # ==== Example
142
+ #
143
+ # append_file 'config/environments/test.rb', 'config.gem "rspec"'
144
+ #
145
+ # append_file 'config/environments/test.rb' do
146
+ # 'config.gem "rspec"'
147
+ # end
148
+ #
149
+ def append_file(path, *args, &block)
150
+ config = args.last.is_a?(Hash) ? args.pop : {}
151
+ config.merge!(:before => /\z/)
152
+ inject_into_file(path, *(args << config), &block)
153
+ end
154
+
155
+ # Injects text right after the class definition. Since it depends on
156
+ # inject_into_file, it's reversible.
157
+ #
158
+ # ==== Parameters
159
+ # path<String>:: path of the file to be changed
160
+ # klass<String|Class>:: the class to be manipulated
161
+ # data<String>:: the data to append to the class, can be also given as a block.
162
+ # config<Hash>:: give :verbose => false to not log the status.
163
+ #
164
+ # ==== Examples
165
+ #
166
+ # inject_into_class "app/controllers/application_controller.rb", " filter_parameter :password\n"
167
+ #
168
+ # inject_into_class "app/controllers/application_controller.rb", ApplicationController do
169
+ # " filter_parameter :password\n"
170
+ # end
171
+ #
172
+ def inject_into_class(path, klass, *args, &block)
173
+ config = args.last.is_a?(Hash) ? args.pop : {}
174
+ config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/)
175
+ inject_into_file(path, *(args << config), &block)
176
+ end
177
+
178
+ # Run a regular expression replacement on a file.
179
+ #
180
+ # ==== Parameters
181
+ # path<String>:: path of the file to be changed
182
+ # flag<Regexp|String>:: the regexp or string to be replaced
183
+ # replacement<String>:: the replacement, can be also given as a block
184
+ # config<Hash>:: give :verbose => false to not log the status.
185
+ #
186
+ # ==== Example
187
+ #
188
+ # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
189
+ #
190
+ # gsub_file 'README', /rake/, :green do |match|
191
+ # match << " no more. Use thor!"
192
+ # end
193
+ #
194
+ def gsub_file(path, flag, *args, &block)
195
+ return unless behavior == :invoke
196
+ config = args.last.is_a?(Hash) ? args.pop : {}
197
+
198
+ path = File.expand_path(path, destination_root)
199
+ say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
200
+
201
+ unless options[:pretend]
202
+ content = File.binread(path)
203
+ content.gsub!(flag, *args, &block)
204
+ File.open(path, 'wb') { |file| file.write(content) }
205
+ end
206
+ end
207
+
208
+ # Removes a file at the given location.
209
+ #
210
+ # ==== Parameters
211
+ # path<String>:: path of the file to be changed
212
+ # config<Hash>:: give :verbose => false to not log the status.
213
+ #
214
+ # ==== Example
215
+ #
216
+ # remove_file 'README'
217
+ # remove_file 'app/controllers/application_controller.rb'
218
+ #
219
+ def remove_file(path, config={})
220
+ return unless behavior == :invoke
221
+ path = File.expand_path(path, destination_root)
222
+
223
+ say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
224
+ ::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path)
225
+ end
226
+ alias :remove_dir :remove_file
227
+
228
+ end
229
+ end