engineyard 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/lib/engineyard.rb +1 -17
  2. data/lib/engineyard/account.rb +13 -49
  3. data/lib/engineyard/account/app.rb +18 -0
  4. data/lib/engineyard/account/app_master.rb +12 -0
  5. data/lib/engineyard/account/environment.rb +31 -0
  6. data/lib/engineyard/account/log.rb +18 -0
  7. data/lib/engineyard/api.rb +4 -2
  8. data/lib/engineyard/cli.rb +34 -11
  9. data/lib/engineyard/cli/ui.rb +1 -1
  10. data/spec/engineyard/api_spec.rb +6 -6
  11. data/spec/engineyard/cli/api_spec.rb +1 -1
  12. data/spec/engineyard/config_spec.rb +9 -9
  13. data/spec/ey/deploy_spec.rb +40 -21
  14. data/spec/ey/logs_spec.rb +28 -0
  15. data/spec/spec_helper.rb +12 -13
  16. data/spec/support/fake_awsm.ru +251 -0
  17. data/spec/support/helpers.rb +50 -38
  18. data/spec/support/ruby_ext.rb +29 -0
  19. metadata +52 -102
  20. data/lib/vendor/thor.rb +0 -244
  21. data/lib/vendor/thor/actions.rb +0 -275
  22. data/lib/vendor/thor/actions/create_file.rb +0 -103
  23. data/lib/vendor/thor/actions/directory.rb +0 -91
  24. data/lib/vendor/thor/actions/empty_directory.rb +0 -134
  25. data/lib/vendor/thor/actions/file_manipulation.rb +0 -223
  26. data/lib/vendor/thor/actions/inject_into_file.rb +0 -104
  27. data/lib/vendor/thor/base.rb +0 -540
  28. data/lib/vendor/thor/core_ext/file_binary_read.rb +0 -9
  29. data/lib/vendor/thor/core_ext/hash_with_indifferent_access.rb +0 -75
  30. data/lib/vendor/thor/core_ext/ordered_hash.rb +0 -100
  31. data/lib/vendor/thor/error.rb +0 -30
  32. data/lib/vendor/thor/group.rb +0 -271
  33. data/lib/vendor/thor/invocation.rb +0 -180
  34. data/lib/vendor/thor/parser.rb +0 -4
  35. data/lib/vendor/thor/parser/argument.rb +0 -67
  36. data/lib/vendor/thor/parser/arguments.rb +0 -150
  37. data/lib/vendor/thor/parser/option.rb +0 -128
  38. data/lib/vendor/thor/parser/options.rb +0 -169
  39. data/lib/vendor/thor/rake_compat.rb +0 -66
  40. data/lib/vendor/thor/runner.rb +0 -314
  41. data/lib/vendor/thor/shell.rb +0 -83
  42. data/lib/vendor/thor/shell/basic.rb +0 -239
  43. data/lib/vendor/thor/shell/color.rb +0 -108
  44. data/lib/vendor/thor/task.rb +0 -102
  45. data/lib/vendor/thor/util.rb +0 -230
  46. data/lib/vendor/thor/version.rb +0 -3
@@ -1,275 +0,0 @@
1
- require 'fileutils'
2
- require 'thor/core_ext/file_binary_read'
3
-
4
- Dir[File.join(File.dirname(__FILE__), "actions", "*.rb")].each do |action|
5
- require action
6
- end
7
-
8
- class Thor
9
- module Actions
10
- attr_accessor :behavior
11
-
12
- def self.included(base) #:nodoc:
13
- base.extend ClassMethods
14
- end
15
-
16
- module ClassMethods
17
- # Hold source paths for one Thor instance. source_paths_for_search is the
18
- # method responsible to gather source_paths from this current class,
19
- # inherited paths and the source root.
20
- #
21
- def source_paths
22
- @source_paths ||= []
23
- end
24
-
25
- # Returns the source paths in the following order:
26
- #
27
- # 1) This class source paths
28
- # 2) Source root
29
- # 3) Parents source paths
30
- #
31
- def source_paths_for_search
32
- paths = []
33
- paths += self.source_paths
34
- paths << self.source_root if self.respond_to?(:source_root)
35
- paths += from_superclass(:source_paths, [])
36
- paths
37
- end
38
-
39
- # Add runtime options that help actions execution.
40
- #
41
- def add_runtime_options!
42
- class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
43
- :desc => "Overwrite files that already exist"
44
-
45
- class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
46
- :desc => "Run but do not make any changes"
47
-
48
- class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
49
- :desc => "Supress status output"
50
-
51
- class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
52
- :desc => "Skip files that already exist"
53
- end
54
- end
55
-
56
- # Extends initializer to add more configuration options.
57
- #
58
- # ==== Configuration
59
- # behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
60
- # It also accepts :force, :skip and :pretend to set the behavior
61
- # and the respective option.
62
- #
63
- # destination_root<String>:: The root directory needed for some actions.
64
- #
65
- def initialize(args=[], options={}, config={})
66
- self.behavior = case config[:behavior].to_s
67
- when "force", "skip"
68
- _cleanup_options_and_set(options, config[:behavior])
69
- :invoke
70
- when "revoke"
71
- :revoke
72
- else
73
- :invoke
74
- end
75
-
76
- super
77
- self.destination_root = config[:destination_root]
78
- end
79
-
80
- # Wraps an action object and call it accordingly to the thor class behavior.
81
- #
82
- def action(instance) #:nodoc:
83
- if behavior == :revoke
84
- instance.revoke!
85
- else
86
- instance.invoke!
87
- end
88
- end
89
-
90
- # Returns the root for this thor class (also aliased as destination root).
91
- #
92
- def destination_root
93
- @destination_stack.last
94
- end
95
-
96
- # Sets the root for this thor class. Relatives path are added to the
97
- # directory where the script was invoked and expanded.
98
- #
99
- def destination_root=(root)
100
- @destination_stack ||= []
101
- @destination_stack[0] = File.expand_path(root || '')
102
- end
103
-
104
- # Returns the given path relative to the absolute root (ie, root where
105
- # the script started).
106
- #
107
- def relative_to_original_destination_root(path, remove_dot=true)
108
- path = path.gsub(@destination_stack[0], '.')
109
- remove_dot ? (path[2..-1] || '') : path
110
- end
111
-
112
- # Holds source paths in instance so they can be manipulated.
113
- #
114
- def source_paths
115
- @source_paths ||= self.class.source_paths_for_search
116
- end
117
-
118
- # Receives a file or directory and search for it in the source paths.
119
- #
120
- def find_in_source_paths(file)
121
- relative_root = relative_to_original_destination_root(destination_root, false)
122
-
123
- source_paths.each do |source|
124
- source_file = File.expand_path(file, File.join(source, relative_root))
125
- return source_file if File.exists?(source_file)
126
- end
127
-
128
- if source_paths.empty?
129
- raise Error, "You don't have any source path defined for class #{self.class.name}. To fix this, " <<
130
- "you can define a source_root in your class."
131
- else
132
- raise Error, "Could not find #{file.inspect} in source paths."
133
- end
134
- end
135
-
136
- # Do something in the root or on a provided subfolder. If a relative path
137
- # is given it's referenced from the current root. The full path is yielded
138
- # to the block you provide. The path is set back to the previous path when
139
- # the method exits.
140
- #
141
- # ==== Parameters
142
- # dir<String>:: the directory to move to.
143
- # config<Hash>:: give :verbose => true to log and use padding.
144
- #
145
- def inside(dir='', config={}, &block)
146
- verbose = config.fetch(:verbose, false)
147
-
148
- say_status :inside, dir, verbose
149
- shell.padding += 1 if verbose
150
- @destination_stack.push File.expand_path(dir, destination_root)
151
-
152
- FileUtils.mkdir_p(destination_root) unless File.exist?(destination_root)
153
- FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
154
-
155
- @destination_stack.pop
156
- shell.padding -= 1 if verbose
157
- end
158
-
159
- # Goes to the root and execute the given block.
160
- #
161
- def in_root
162
- inside(@destination_stack.first) { yield }
163
- end
164
-
165
- # Loads an external file and execute it in the instance binding.
166
- #
167
- # ==== Parameters
168
- # path<String>:: The path to the file to execute. Can be a web address or
169
- # a relative path from the source root.
170
- #
171
- # ==== Examples
172
- #
173
- # apply "http://gist.github.com/103208"
174
- #
175
- # apply "recipes/jquery.rb"
176
- #
177
- def apply(path, config={})
178
- verbose = config.fetch(:verbose, true)
179
- path = find_in_source_paths(path) unless path =~ /^http\:\/\//
180
-
181
- say_status :apply, path, verbose
182
- shell.padding += 1 if verbose
183
- instance_eval(open(path).read)
184
- shell.padding -= 1 if verbose
185
- end
186
-
187
- # Executes a command returning the contents of the command.
188
- #
189
- # ==== Parameters
190
- # command<String>:: the command to be executed.
191
- # config<Hash>:: give :verbose => false to not log the status. Specify :with
192
- # to append an executable to command executation.
193
- #
194
- # ==== Example
195
- #
196
- # inside('vendor') do
197
- # run('ln -s ~/edge rails')
198
- # end
199
- #
200
- def run(command, config={})
201
- return unless behavior == :invoke
202
-
203
- destination = relative_to_original_destination_root(destination_root, false)
204
- desc = "#{command} from #{destination.inspect}"
205
-
206
- if config[:with]
207
- desc = "#{File.basename(config[:with].to_s)} #{desc}"
208
- command = "#{config[:with]} #{command}"
209
- end
210
-
211
- say_status :run, desc, config.fetch(:verbose, true)
212
- `#{command}` unless options[:pretend]
213
- end
214
-
215
- # Executes a ruby script (taking into account WIN32 platform quirks).
216
- #
217
- # ==== Parameters
218
- # command<String>:: the command to be executed.
219
- # config<Hash>:: give :verbose => false to not log the status.
220
- #
221
- def run_ruby_script(command, config={})
222
- return unless behavior == :invoke
223
- run command, config.merge(:with => Thor::Util.ruby_command)
224
- end
225
-
226
- # Run a thor command. A hash of options can be given and it's converted to
227
- # switches.
228
- #
229
- # ==== Parameters
230
- # task<String>:: the task to be invoked
231
- # args<Array>:: arguments to the task
232
- # config<Hash>:: give :verbose => false to not log the status. Other options
233
- # are given as parameter to Thor.
234
- #
235
- # ==== Examples
236
- #
237
- # thor :install, "http://gist.github.com/103208"
238
- # #=> thor install http://gist.github.com/103208
239
- #
240
- # thor :list, :all => true, :substring => 'rails'
241
- # #=> thor list --all --substring=rails
242
- #
243
- def thor(task, *args)
244
- config = args.last.is_a?(Hash) ? args.pop : {}
245
- verbose = config.key?(:verbose) ? config.delete(:verbose) : true
246
- pretend = config.key?(:pretend) ? config.delete(:pretend) : false
247
-
248
- args.unshift task
249
- args.push Thor::Options.to_switches(config)
250
- command = args.join(' ').strip
251
-
252
- run command, :with => :thor, :verbose => verbose, :pretend => pretend
253
- end
254
-
255
- protected
256
-
257
- # Allow current root to be shared between invocations.
258
- #
259
- def _shared_configuration #:nodoc:
260
- super.merge!(:destination_root => self.destination_root)
261
- end
262
-
263
- def _cleanup_options_and_set(options, key) #:nodoc:
264
- case options
265
- when Array
266
- %w(--force -f --skip -s).each { |i| options.delete(i) }
267
- options << "--#{key}"
268
- when Hash
269
- [:force, :skip, "force", "skip"].each { |i| options.delete(i) }
270
- options.merge!(key => true)
271
- end
272
- end
273
-
274
- end
275
- end
@@ -1,103 +0,0 @@
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, data=nil, config={}, &block)
24
- action CreateFile.new(self, destination, block || data.to_s, config)
25
- end
26
- alias :add_file :create_file
27
-
28
- # AddFile is a subset of Template, which instead of rendering a file with
29
- # ERB, it gets the content from the user.
30
- #
31
- class CreateFile < EmptyDirectory #:nodoc:
32
- attr_reader :data
33
-
34
- def initialize(base, destination, data, config={})
35
- @data = data
36
- super(base, destination, config)
37
- end
38
-
39
- # Checks if the content of the file at the destination is identical to the rendered result.
40
- #
41
- # ==== Returns
42
- # Boolean:: true if it is identical, false otherwise.
43
- #
44
- def identical?
45
- exists? && File.binread(destination) == render
46
- end
47
-
48
- # Holds the content to be added to the file.
49
- #
50
- def render
51
- @render ||= if data.is_a?(Proc)
52
- data.call
53
- else
54
- data
55
- end
56
- end
57
-
58
- def invoke!
59
- invoke_with_conflict_check do
60
- FileUtils.mkdir_p(File.dirname(destination))
61
- File.open(destination, 'wb') { |f| f.write render }
62
- end
63
- given_destination
64
- end
65
-
66
- protected
67
-
68
- # Now on conflict we check if the file is identical or not.
69
- #
70
- def on_conflict_behavior(&block)
71
- if identical?
72
- say_status :identical, :blue
73
- else
74
- options = base.options.merge(config)
75
- force_or_skip_or_conflict(options[:force], options[:skip], &block)
76
- end
77
- end
78
-
79
- # If force is true, run the action, otherwise check if it's not being
80
- # skipped. If both are false, show the file_collision menu, if the menu
81
- # returns true, force it, otherwise skip.
82
- #
83
- def force_or_skip_or_conflict(force, skip, &block)
84
- if force
85
- say_status :force, :yellow
86
- block.call unless pretend?
87
- elsif skip
88
- say_status :skip, :yellow
89
- else
90
- say_status :conflict, :red
91
- force_or_skip_or_conflict(force_on_collision?, true, &block)
92
- end
93
- end
94
-
95
- # Shows the file collision menu to the user and gets the result.
96
- #
97
- def force_on_collision?
98
- base.shell.file_collision(destination){ render }
99
- end
100
-
101
- end
102
- end
103
- end
@@ -1,91 +0,0 @@
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, destination=nil, config={}, &block)
44
- action Directory.new(self, source, destination || source, config, &block)
45
- end
46
-
47
- class Directory < EmptyDirectory #:nodoc:
48
- attr_reader :source
49
-
50
- def initialize(base, source, destination=nil, config={}, &block)
51
- @source = File.expand_path(base.find_in_source_paths(source.to_s))
52
- @block = block
53
- super(base, destination, { :recursive => true }.merge(config))
54
- end
55
-
56
- def invoke!
57
- base.empty_directory given_destination, config
58
- execute!
59
- end
60
-
61
- def revoke!
62
- execute!
63
- end
64
-
65
- protected
66
-
67
- def execute!
68
- lookup = config[:recursive] ? File.join(source, '**') : source
69
- lookup = File.join(lookup, '{*,.[a-z]*}')
70
-
71
- Dir[lookup].each do |file_source|
72
- next if File.directory?(file_source)
73
- file_destination = File.join(given_destination, file_source.gsub(source, '.'))
74
- file_destination.gsub!('/./', '/')
75
-
76
- case file_source
77
- when /\.empty_directory$/
78
- dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
79
- next if dirname == given_destination
80
- base.empty_directory(dirname, config)
81
- when /\.tt$/
82
- destination = base.template(file_source, file_destination[0..-4], config, &@block)
83
- else
84
- destination = base.copy_file(file_source, file_destination, config, &@block)
85
- end
86
- end
87
- end
88
-
89
- end
90
- end
91
- end