Skip to content
This repository
Browse code

extracted logging and system command execution

to method
  • Loading branch information...
commit 6f12a73e57cedc38cb1613362dac2c50967e6ad5 1 parent b8a9b18
Despo Pentara despo authored

Showing 1 changed file with 31 additions and 24 deletions. Show diff stats Hide diff stats

  1. +31 24 lib/capistrano/recipes/deploy/strategy/copy.rb
55 lib/capistrano/recipes/deploy/strategy/copy.rb
@@ -76,11 +76,8 @@ def deploy!
76 76 def build(directory)
77 77 return unless configuration[:build_script]
78 78
79   - logger.debug "running build script on #{directory}"
80   - Dir.chdir(directory) do
81   - self.system(configuration[:build_script])
82   -
83   - raise_command_failed if last_command_failed?
  79 + execute "running build script on #{directory}" do
  80 + Dir.chdir(directory) { self.system(configuration[:build_script]) }
84 81 end
85 82 end
86 83
@@ -104,14 +101,26 @@ def copy_cache
104 101
105 102 private
106 103
  104 + def execute description, &block
  105 + logger.debug description
  106 + handle_system_errors &block
  107 + end
  108 +
  109 + def handle_system_errors &block
  110 + block.call
  111 + raise_command_failed if last_command_failed?
  112 + end
  113 +
107 114 def refresh_local_cache
108   - logger.debug "refreshing local cache to revision #{revision} at #{copy_cache}"
109   - system(source.sync(revision, copy_cache))
  115 + execute "refreshing local cache to revision #{revision} at #{copy_cache}" do
  116 + system(source.sync(revision, copy_cache))
  117 + end
110 118 end
111 119
112 120 def create_local_cache
113   - logger.debug "preparing local cache at #{copy_cache}"
114   - system(source.checkout(revision, copy_cache))
  121 + execute "preparing local cache at #{copy_cache}" do
  122 + system(source.checkout(revision, copy_cache))
  123 + end
115 124 end
116 125
117 126 def raise_command_failed
@@ -123,11 +132,12 @@ def last_command_failed?
123 132 end
124 133
125 134 def copy_cache_to_staging_area
126   - logger.debug "copying cache to deployment staging area #{destination}"
127   - create_destination
  135 + execute "copying cache to deployment staging area #{destination}" do
  136 + create_destination
128 137
129   - Dir.chdir(copy_cache) do
130   - copy_files(queue_files)
  138 + Dir.chdir(copy_cache) do
  139 + copy_files(queue_files)
  140 + end
131 141 end
132 142 end
133 143
@@ -171,8 +181,9 @@ def excluded_files_contain? file
171 181 end
172 182
173 183 def copy_repository_to_server
174   - logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
175   - system(command)
  184 + execute "getting (via #{copy_strategy}) revision #{revision} to #{destination}" do
  185 + system(command)
  186 + end
176 187 end
177 188
178 189 def remove_excluded_files
@@ -191,8 +202,9 @@ def create_revision_file
191 202 end
192 203
193 204 def compress_repository
194   - logger.trace "compressing #{destination} to #{filename}"
195   - Dir.chdir(copy_dir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }
  205 + execute "Compressing #{destination} to #{filename}" do
  206 + Dir.chdir(copy_dir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }
  207 + end
196 208 end
197 209
198 210 def rollback_changes
@@ -201,13 +213,8 @@ def rollback_changes
201 213 end
202 214
203 215 def copy_repository_to_local_cache
204   - if File.exists?(copy_cache)
205   - refresh_local_cache
206   - else
207   - create_local_cache
208   - end
209   -
210   - raise_command_failed if last_command_failed?
  216 + return refresh_local_cache if File.exists?(copy_cache)
  217 + create_local_cache
211 218 end
212 219
213 220 # Specify patterns to exclude from the copy. This is only valid

0 comments on commit 6f12a73

Please sign in to comment.
Something went wrong with that request. Please try again.