Permalink
Browse files

make user an optional setting

  • Loading branch information...
1 parent 920673f commit 7a2e0d04444f82e286a9e91fb46fb5e2cbcf03a8 @tilsammans committed Aug 4, 2011
Showing with 14 additions and 9 deletions.
  1. +1 −1 capistrano_transmit.gemspec
  2. +13 −8 lib/capistrano/transmit.rb
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{capistrano_transmit}
- s.version = "0.2.2"
+ s.version = "0.2.6"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Joost Baaij"]
@@ -4,28 +4,33 @@
Capistrano::Configuration.instance.load do
- _cset :user, ""
- _cset :db_config, { capture("cat #{current_path}/config/database.yml") }
- _cset :db_remote, { YAML::load(db_config)['production'] }
- _cset :db_local, { YAML::load_file("config/database.yml")['development'] }
- _cset :dumpfile, { "#{current_path}/tmp/#{db_remote['database']}.sql.gz" }
+ _cset :user, nil
+ _cset(:db_config) { capture("cat #{current_path}/config/database.yml") }
+ _cset(:db_remote) { YAML::load(db_config)['production'] }
+ _cset(:db_local) { YAML::load_file("config/database.yml")['development'] }
+ _cset(:dumpfile) { "#{current_path}/tmp/#{db_remote['database']}.sql.gz" }
after "transmit:get:mysql", "transmit:cleanup"
after "transmit:put:mysql", "transmit:cleanup"
+ # Return just the deploy host when user not set.
+ def _user_with_host
+ user.nil? ? deploy_host : "#{user}@#{deploy_host}"
+ end
+
namespace :transmit do
namespace :get do
desc 'Fetch the remote production database and overwrite your local development database with it'
task :mysql, :roles => :db do
run "mysqldump --opt --quick --extended-insert --skip-lock-tables -u #{db_remote['username']} --password='#{db_remote['password']}' --host='#{db_remote['host']}' #{db_remote['database']} | gzip > #{dumpfile}"
- system "rsync -vP #{user}@#{deploy_host}:#{dumpfile} tmp/#{db_local["database"]}.sql.gz"
+ system "rsync -vP #{_user_with_host}:#{dumpfile} tmp/#{db_local["database"]}.sql.gz"
system "gunzip < tmp/#{db_local["database"]}.sql.gz | mysql -u #{db_local['username']} --password='#{db_local['password']}' --host='#{db_local['host']}' #{db_local['database']}"
end
desc 'Fetch the assets from the production server to the development environment'
task :assets, :roles => :app do
- system "rsync -Lcrvz #{user}@#{deploy_host}:#{current_path}/public ."
+ system "rsync -Lcrvz #{_user_with_host}:#{current_path}/public ."
end
end
@@ -34,7 +39,7 @@
task :mysql, :roles => :db do
system "mysqldump --opt -u #{db_local['username']} --password='#{db_local['password']}' --host='#{db_local['host']}' #{db_local['database']} > tmp/#{db_local['database']}.sql"
- system "rsync -vP tmp/#{db_local['database']}.sql #{user}@#{deploy_host}:#{dumpfile}"
+ system "rsync -vP tmp/#{db_local['database']}.sql #{_user_with_host}:#{dumpfile}"
run "mysql -u #{db_remote['username']} --password='#{db_remote['password']}' --host='#{db_remote['host']}' #{db_remote['database']} < #{dumpfile}"
end
end

0 comments on commit 7a2e0d0

Please sign in to comment.