engineyard-serverside 1.5.21 → 1.5.23.ruby19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/lib/engineyard-serverside/cli.rb +39 -45
  2. data/lib/engineyard-serverside/configuration.rb +28 -4
  3. data/lib/engineyard-serverside/deploy.rb +5 -4
  4. data/lib/engineyard-serverside/logged_output.rb +3 -5
  5. data/lib/engineyard-serverside/server.rb +26 -2
  6. data/lib/engineyard-serverside/task.rb +2 -4
  7. data/lib/engineyard-serverside/version.rb +1 -1
  8. data/lib/engineyard-serverside.rb +8 -20
  9. data/spec/basic_deploy_spec.rb +1 -1
  10. data/spec/bundler_deploy_spec.rb +1 -1
  11. data/spec/nodejs_deploy_spec.rb +1 -1
  12. data/spec/rails31_deploy_spec.rb +1 -1
  13. data/spec/services_deploy_spec.rb +1 -1
  14. metadata +80 -233
  15. data/lib/vendor/dataflow/HISTORY +0 -52
  16. data/lib/vendor/dataflow/LICENSE +0 -19
  17. data/lib/vendor/dataflow/README.textile +0 -290
  18. data/lib/vendor/dataflow/Rakefile +0 -36
  19. data/lib/vendor/dataflow/dataflow/actor.rb +0 -22
  20. data/lib/vendor/dataflow/dataflow/equality.rb +0 -44
  21. data/lib/vendor/dataflow/dataflow/future_queue.rb +0 -24
  22. data/lib/vendor/dataflow/dataflow/port.rb +0 -54
  23. data/lib/vendor/dataflow/dataflow.rb +0 -124
  24. data/lib/vendor/dataflow/examples/barrier.rb +0 -9
  25. data/lib/vendor/dataflow/examples/data_driven.rb +0 -17
  26. data/lib/vendor/dataflow/examples/dataflow_http_gets.rb +0 -13
  27. data/lib/vendor/dataflow/examples/flow.rb +0 -20
  28. data/lib/vendor/dataflow/examples/future_http_gets.rb +0 -12
  29. data/lib/vendor/dataflow/examples/future_queue.rb +0 -11
  30. data/lib/vendor/dataflow/examples/instance_variables.rb +0 -15
  31. data/lib/vendor/dataflow/examples/laziness.rb +0 -9
  32. data/lib/vendor/dataflow/examples/local_variables.rb +0 -11
  33. data/lib/vendor/dataflow/examples/messages.rb +0 -26
  34. data/lib/vendor/dataflow/examples/port_http_gets.rb +0 -13
  35. data/lib/vendor/dataflow/examples/port_send.rb +0 -10
  36. data/lib/vendor/dataflow/examples/ring.rb +0 -21
  37. data/lib/vendor/dataflow/spec/actor_spec.rb +0 -28
  38. data/lib/vendor/dataflow/spec/anonymous_variables_spec.rb +0 -21
  39. data/lib/vendor/dataflow/spec/barrier_spec.rb +0 -25
  40. data/lib/vendor/dataflow/spec/by_need_spec.rb +0 -55
  41. data/lib/vendor/dataflow/spec/dataflow_spec.rb +0 -151
  42. data/lib/vendor/dataflow/spec/equality_spec.rb +0 -40
  43. data/lib/vendor/dataflow/spec/flow_spec.rb +0 -25
  44. data/lib/vendor/dataflow/spec/forker_spec.rb +0 -28
  45. data/lib/vendor/dataflow/spec/future_queue_spec.rb +0 -31
  46. data/lib/vendor/dataflow/spec/inspect_spec.rb +0 -19
  47. data/lib/vendor/dataflow/spec/need_later_spec.rb +0 -12
  48. data/lib/vendor/dataflow/spec/port_spec.rb +0 -26
  49. data/lib/vendor/dataflow/spec/spec.opts +0 -1
  50. data/lib/vendor/dataflow/spec/spec_helper.rb +0 -10
  51. data/lib/vendor/escape/Readme +0 -21
  52. data/lib/vendor/escape/doc_include/template/qualitysmith.rb +0 -631
  53. data/lib/vendor/json_pure/CHANGES +0 -166
  54. data/lib/vendor/json_pure/COPYING +0 -58
  55. data/lib/vendor/json_pure/GPL +0 -340
  56. data/lib/vendor/json_pure/README +0 -358
  57. data/lib/vendor/json_pure/Rakefile +0 -292
  58. data/lib/vendor/json_pure/TODO +0 -1
  59. data/lib/vendor/json_pure/VERSION +0 -1
  60. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +0 -52
  61. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +0 -1000
  62. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +0 -1001
  63. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +0 -900
  64. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +0 -901
  65. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +0 -1000
  66. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +0 -1001
  67. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +0 -261
  68. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +0 -1000
  69. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +0 -1001
  70. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +0 -1000
  71. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +0 -1001
  72. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +0 -1000
  73. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +0 -1001
  74. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +0 -262
  75. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +0 -1000
  76. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +0 -1001
  77. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +0 -82
  78. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +0 -34
  79. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +0 -900
  80. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +0 -901
  81. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +0 -81
  82. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +0 -1000
  83. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +0 -1001
  84. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +0 -82
  85. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +0 -1000
  86. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +0 -1001
  87. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +0 -82
  88. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +0 -1000
  89. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +0 -1001
  90. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +0 -82
  91. data/lib/vendor/json_pure/benchmarks/generator2_benchmark.rb +0 -222
  92. data/lib/vendor/json_pure/benchmarks/generator_benchmark.rb +0 -224
  93. data/lib/vendor/json_pure/benchmarks/ohai.json +0 -1216
  94. data/lib/vendor/json_pure/benchmarks/ohai.ruby +0 -1
  95. data/lib/vendor/json_pure/benchmarks/parser2_benchmark.rb +0 -251
  96. data/lib/vendor/json_pure/benchmarks/parser_benchmark.rb +0 -259
  97. data/lib/vendor/json_pure/bin/edit_json.rb +0 -9
  98. data/lib/vendor/json_pure/bin/prettify_json.rb +0 -75
  99. data/lib/vendor/json_pure/data/example.json +0 -1
  100. data/lib/vendor/json_pure/data/index.html +0 -38
  101. data/lib/vendor/json_pure/data/prototype.js +0 -4184
  102. data/lib/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -16
  103. data/lib/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1323
  104. data/lib/vendor/json_pure/ext/json/ext/generator/generator.h +0 -170
  105. data/lib/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -15
  106. data/lib/vendor/json_pure/ext/json/ext/parser/parser.c +0 -1935
  107. data/lib/vendor/json_pure/ext/json/ext/parser/parser.h +0 -71
  108. data/lib/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -792
  109. data/lib/vendor/json_pure/install.rb +0 -26
  110. data/lib/vendor/json_pure/tests/fixtures/fail1.json +0 -1
  111. data/lib/vendor/json_pure/tests/fixtures/fail10.json +0 -1
  112. data/lib/vendor/json_pure/tests/fixtures/fail11.json +0 -1
  113. data/lib/vendor/json_pure/tests/fixtures/fail12.json +0 -1
  114. data/lib/vendor/json_pure/tests/fixtures/fail13.json +0 -1
  115. data/lib/vendor/json_pure/tests/fixtures/fail14.json +0 -1
  116. data/lib/vendor/json_pure/tests/fixtures/fail18.json +0 -1
  117. data/lib/vendor/json_pure/tests/fixtures/fail19.json +0 -1
  118. data/lib/vendor/json_pure/tests/fixtures/fail2.json +0 -1
  119. data/lib/vendor/json_pure/tests/fixtures/fail20.json +0 -1
  120. data/lib/vendor/json_pure/tests/fixtures/fail21.json +0 -1
  121. data/lib/vendor/json_pure/tests/fixtures/fail22.json +0 -1
  122. data/lib/vendor/json_pure/tests/fixtures/fail23.json +0 -1
  123. data/lib/vendor/json_pure/tests/fixtures/fail24.json +0 -1
  124. data/lib/vendor/json_pure/tests/fixtures/fail25.json +0 -1
  125. data/lib/vendor/json_pure/tests/fixtures/fail27.json +0 -2
  126. data/lib/vendor/json_pure/tests/fixtures/fail28.json +0 -2
  127. data/lib/vendor/json_pure/tests/fixtures/fail3.json +0 -1
  128. data/lib/vendor/json_pure/tests/fixtures/fail4.json +0 -1
  129. data/lib/vendor/json_pure/tests/fixtures/fail5.json +0 -1
  130. data/lib/vendor/json_pure/tests/fixtures/fail6.json +0 -1
  131. data/lib/vendor/json_pure/tests/fixtures/fail7.json +0 -1
  132. data/lib/vendor/json_pure/tests/fixtures/fail8.json +0 -1
  133. data/lib/vendor/json_pure/tests/fixtures/fail9.json +0 -1
  134. data/lib/vendor/json_pure/tests/fixtures/pass1.json +0 -56
  135. data/lib/vendor/json_pure/tests/fixtures/pass15.json +0 -1
  136. data/lib/vendor/json_pure/tests/fixtures/pass16.json +0 -1
  137. data/lib/vendor/json_pure/tests/fixtures/pass17.json +0 -1
  138. data/lib/vendor/json_pure/tests/fixtures/pass2.json +0 -1
  139. data/lib/vendor/json_pure/tests/fixtures/pass26.json +0 -1
  140. data/lib/vendor/json_pure/tests/fixtures/pass3.json +0 -6
  141. data/lib/vendor/json_pure/tests/test_json.rb +0 -361
  142. data/lib/vendor/json_pure/tests/test_json_addition.rb +0 -162
  143. data/lib/vendor/json_pure/tests/test_json_encoding.rb +0 -68
  144. data/lib/vendor/json_pure/tests/test_json_fixtures.rb +0 -34
  145. data/lib/vendor/json_pure/tests/test_json_generate.rb +0 -122
  146. data/lib/vendor/json_pure/tests/test_json_rails.rb +0 -144
  147. data/lib/vendor/json_pure/tests/test_json_unicode.rb +0 -76
  148. data/lib/vendor/json_pure/tools/fuzz.rb +0 -139
  149. data/lib/vendor/json_pure/tools/server.rb +0 -61
  150. data/lib/vendor/open4/lib/open4.rb +0 -403
  151. data/lib/vendor/thor/CHANGELOG.rdoc +0 -89
  152. data/lib/vendor/thor/LICENSE +0 -20
  153. data/lib/vendor/thor/README.rdoc +0 -297
  154. data/lib/vendor/thor/Thorfile +0 -69
  155. data/lib/vendor/thor/bin/rake2thor +0 -86
  156. data/lib/vendor/thor/bin/thor +0 -6
  157. data/lib/vendor/thor/lib/thor/actions/create_file.rb +0 -103
  158. data/lib/vendor/thor/lib/thor/actions/directory.rb +0 -91
  159. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +0 -134
  160. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +0 -223
  161. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +0 -104
  162. data/lib/vendor/thor/lib/thor/actions.rb +0 -275
  163. data/lib/vendor/thor/lib/thor/base.rb +0 -540
  164. data/lib/vendor/thor/lib/thor/core_ext/file_binary_read.rb +0 -9
  165. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -75
  166. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +0 -100
  167. data/lib/vendor/thor/lib/thor/error.rb +0 -30
  168. data/lib/vendor/thor/lib/thor/group.rb +0 -271
  169. data/lib/vendor/thor/lib/thor/invocation.rb +0 -180
  170. data/lib/vendor/thor/lib/thor/parser/argument.rb +0 -67
  171. data/lib/vendor/thor/lib/thor/parser/arguments.rb +0 -150
  172. data/lib/vendor/thor/lib/thor/parser/option.rb +0 -128
  173. data/lib/vendor/thor/lib/thor/parser/options.rb +0 -169
  174. data/lib/vendor/thor/lib/thor/parser.rb +0 -4
  175. data/lib/vendor/thor/lib/thor/rake_compat.rb +0 -66
  176. data/lib/vendor/thor/lib/thor/runner.rb +0 -314
  177. data/lib/vendor/thor/lib/thor/shell/basic.rb +0 -239
  178. data/lib/vendor/thor/lib/thor/shell/color.rb +0 -108
  179. data/lib/vendor/thor/lib/thor/shell.rb +0 -83
  180. data/lib/vendor/thor/lib/thor/task.rb +0 -102
  181. data/lib/vendor/thor/lib/thor/util.rb +0 -230
  182. data/lib/vendor/thor/lib/thor/version.rb +0 -3
  183. data/lib/vendor/thor/lib/thor.rb +0 -244
  184. data/lib/vendor/thor/thor.gemspec +0 -120
@@ -1,134 +0,0 @@
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
@@ -1,223 +0,0 @@
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, destination=nil, config={}, &block)
22
- destination ||= source
23
- source = File.expand_path(find_in_source_paths(source.to_s))
24
-
25
- create_file destination, nil, config do
26
- content = File.binread(source)
27
- content = block.call(content) if block
28
- content
29
- end
30
- end
31
-
32
- # Gets the content at the given address and places it at the given relative
33
- # destination. If a block is given instead of destination, the content of
34
- # the url is yielded and used as location.
35
- #
36
- # ==== Parameters
37
- # source<String>:: the address of the given content.
38
- # destination<String>:: the relative path to the destination root.
39
- # config<Hash>:: give :verbose => false to not log the status.
40
- #
41
- # ==== Examples
42
- #
43
- # get "http://gist.github.com/103208", "doc/README"
44
- #
45
- # get "http://gist.github.com/103208" do |content|
46
- # content.split("\n").first
47
- # end
48
- #
49
- def get(source, destination=nil, config={}, &block)
50
- source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^http\:\/\//
51
- render = open(source).binmode.read
52
-
53
- destination ||= if block_given?
54
- block.arity == 1 ? block.call(render) : block.call
55
- else
56
- File.basename(source)
57
- end
58
-
59
- create_file destination, render, config
60
- end
61
-
62
- # Gets an ERB template at the relative source, executes it and makes a copy
63
- # at the relative destination. If the destination is not given it's assumed
64
- # to be equal to the source removing .tt from the filename.
65
- #
66
- # ==== Parameters
67
- # source<String>:: the relative path to the source root.
68
- # destination<String>:: the relative path to the destination root.
69
- # config<Hash>:: give :verbose => false to not log the status.
70
- #
71
- # ==== Examples
72
- #
73
- # template "README", "doc/README"
74
- #
75
- # template "doc/README"
76
- #
77
- def template(source, destination=nil, config={}, &block)
78
- destination ||= source
79
- source = File.expand_path(find_in_source_paths(source.to_s))
80
- context = instance_eval('binding')
81
-
82
- create_file destination, nil, config do
83
- content = ERB.new(::File.binread(source), nil, '-').result(context)
84
- content = block.call(content) if block
85
- content
86
- end
87
- end
88
-
89
- # Changes the mode of the given file or directory.
90
- #
91
- # ==== Parameters
92
- # mode<Integer>:: the file mode
93
- # path<String>:: the name of the file to change mode
94
- # config<Hash>:: give :verbose => false to not log the status.
95
- #
96
- # ==== Example
97
- #
98
- # chmod "script/*", 0755
99
- #
100
- def chmod(path, mode, config={})
101
- return unless behavior == :invoke
102
- path = File.expand_path(path, destination_root)
103
- say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
104
- FileUtils.chmod_R(mode, path) unless options[:pretend]
105
- end
106
-
107
- # Prepend text to a file. Since it depends on inject_into_file, it's reversible.
108
- #
109
- # ==== Parameters
110
- # path<String>:: path of the file to be changed
111
- # data<String>:: the data to prepend to the file, can be also given as a block.
112
- # config<Hash>:: give :verbose => false to not log the status.
113
- #
114
- # ==== Example
115
- #
116
- # prepend_file 'config/environments/test.rb', 'config.gem "rspec"'
117
- #
118
- # prepend_file 'config/environments/test.rb' do
119
- # 'config.gem "rspec"'
120
- # end
121
- #
122
- def prepend_file(path, *args, &block)
123
- config = args.last.is_a?(Hash) ? args.pop : {}
124
- config.merge!(:after => /\A/)
125
- inject_into_file(path, *(args << config), &block)
126
- end
127
-
128
- # Append text to a file. Since it depends on inject_into_file, it's reversible.
129
- #
130
- # ==== Parameters
131
- # path<String>:: path of the file to be changed
132
- # data<String>:: the data to append to the file, can be also given as a block.
133
- # config<Hash>:: give :verbose => false to not log the status.
134
- #
135
- # ==== Example
136
- #
137
- # append_file 'config/environments/test.rb', 'config.gem "rspec"'
138
- #
139
- # append_file 'config/environments/test.rb' do
140
- # 'config.gem "rspec"'
141
- # end
142
- #
143
- def append_file(path, *args, &block)
144
- config = args.last.is_a?(Hash) ? args.pop : {}
145
- config.merge!(:before => /\z/)
146
- inject_into_file(path, *(args << config), &block)
147
- end
148
-
149
- # Injects text right after the class definition. Since it depends on
150
- # inject_into_file, it's reversible.
151
- #
152
- # ==== Parameters
153
- # path<String>:: path of the file to be changed
154
- # klass<String|Class>:: the class to be manipulated
155
- # data<String>:: the data to append to the class, can be also given as a block.
156
- # config<Hash>:: give :verbose => false to not log the status.
157
- #
158
- # ==== Examples
159
- #
160
- # inject_into_class "app/controllers/application_controller.rb", " filter_parameter :password\n"
161
- #
162
- # inject_into_class "app/controllers/application_controller.rb", ApplicationController do
163
- # " filter_parameter :password\n"
164
- # end
165
- #
166
- def inject_into_class(path, klass, *args, &block)
167
- config = args.last.is_a?(Hash) ? args.pop : {}
168
- config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/)
169
- inject_into_file(path, *(args << config), &block)
170
- end
171
-
172
- # Run a regular expression replacement on a file.
173
- #
174
- # ==== Parameters
175
- # path<String>:: path of the file to be changed
176
- # flag<Regexp|String>:: the regexp or string to be replaced
177
- # replacement<String>:: the replacement, can be also given as a block
178
- # config<Hash>:: give :verbose => false to not log the status.
179
- #
180
- # ==== Example
181
- #
182
- # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
183
- #
184
- # gsub_file 'README', /rake/, :green do |match|
185
- # match << " no more. Use thor!"
186
- # end
187
- #
188
- def gsub_file(path, flag, *args, &block)
189
- return unless behavior == :invoke
190
- config = args.last.is_a?(Hash) ? args.pop : {}
191
-
192
- path = File.expand_path(path, destination_root)
193
- say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
194
-
195
- unless options[:pretend]
196
- content = File.binread(path)
197
- content.gsub!(flag, *args, &block)
198
- File.open(path, 'wb') { |file| file.write(content) }
199
- end
200
- end
201
-
202
- # Removes a file at the given location.
203
- #
204
- # ==== Parameters
205
- # path<String>:: path of the file to be changed
206
- # config<Hash>:: give :verbose => false to not log the status.
207
- #
208
- # ==== Example
209
- #
210
- # remove_file 'README'
211
- # remove_file 'app/controllers/application_controller.rb'
212
- #
213
- def remove_file(path, config={})
214
- return unless behavior == :invoke
215
- path = File.expand_path(path, destination_root)
216
-
217
- say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
218
- ::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path)
219
- end
220
- alias :remove_dir :remove_file
221
-
222
- end
223
- end
@@ -1,104 +0,0 @@
1
- require 'thor/actions/empty_directory'
2
-
3
- class Thor
4
- module Actions
5
-
6
- # Injects the given content into a file. Different from gsub_file, this
7
- # method is reversible.
8
- #
9
- # ==== Parameters
10
- # destination<String>:: Relative path to the destination root
11
- # data<String>:: Data to add to the file. Can be given as a block.
12
- # config<Hash>:: give :verbose => false to not log the status and the flag
13
- # for injection (:after or :before) or :force => true for
14
- # insert two or more times the same content.
15
- #
16
- # ==== Examples
17
- #
18
- # inject_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n"
19
- #
20
- # inject_into_file "config/environment.rb", :after => "Rails::Initializer.run do |config|\n" do
21
- # gems = ask "Which gems would you like to add?"
22
- # gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n")
23
- # end
24
- #
25
- def inject_into_file(destination, *args, &block)
26
- if block_given?
27
- data, config = block, args.shift
28
- else
29
- data, config = args.shift, args.shift
30
- end
31
- action InjectIntoFile.new(self, destination, data, config)
32
- end
33
-
34
- class InjectIntoFile < EmptyDirectory #:nodoc:
35
- attr_reader :replacement, :flag, :behavior
36
-
37
- def initialize(base, destination, data, config)
38
- super(base, destination, { :verbose => true }.merge(config))
39
-
40
- @behavior, @flag = if @config.key?(:after)
41
- [:after, @config.delete(:after)]
42
- else
43
- [:before, @config.delete(:before)]
44
- end
45
-
46
- @replacement = data.is_a?(Proc) ? data.call : data
47
- @flag = Regexp.escape(@flag) unless @flag.is_a?(Regexp)
48
- end
49
-
50
- def invoke!
51
- say_status :invoke
52
-
53
- content = if @behavior == :after
54
- '\0' + replacement
55
- else
56
- replacement + '\0'
57
- end
58
-
59
- replace!(/#{flag}/, content, config[:force])
60
- end
61
-
62
- def revoke!
63
- say_status :revoke
64
-
65
- regexp = if @behavior == :after
66
- content = '\1\2'
67
- /(#{flag})(.*)(#{Regexp.escape(replacement)})/m
68
- else
69
- content = '\2\3'
70
- /(#{Regexp.escape(replacement)})(.*)(#{flag})/m
71
- end
72
-
73
- replace!(regexp, content, true)
74
- end
75
-
76
- protected
77
-
78
- def say_status(behavior)
79
- status = if flag == /\A/
80
- behavior == :invoke ? :prepend : :unprepend
81
- elsif flag == /\z/
82
- behavior == :invoke ? :append : :unappend
83
- else
84
- behavior == :invoke ? :inject : :deinject
85
- end
86
-
87
- super(status, config[:verbose])
88
- end
89
-
90
- # Adds the content to the file.
91
- #
92
- def replace!(regexp, string, force)
93
- unless base.options[:pretend]
94
- content = File.binread(destination)
95
- if force || !content.include?(replacement)
96
- content.gsub!(regexp, string)
97
- File.open(destination, 'wb') { |file| file.write(content) }
98
- end
99
- end
100
- end
101
-
102
- end
103
- end
104
- end