diff --git a/lib/capistrano-db-tasks/asset.rb b/lib/capistrano-db-tasks/asset.rb index d40b3b9..c641db6 100644 --- a/lib/capistrano-db-tasks/asset.rb +++ b/lib/capistrano-db-tasks/asset.rb @@ -2,26 +2,37 @@ module Asset extend self def remote_to_local(cap) - servers = Capistrano::Configuration.env.send(:servers) - server = servers.detect { |s| s.roles.include?(:app) } - port = server.netssh_options[:port] || 22 - user = server.netssh_options[:user] - [cap.fetch(:assets_dir)].flatten.each do |dir| - system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' #{user}@#{server}:#{cap.current_path}/#{dir} #{cap.fetch(:local_assets_dir)}") + raise "server with role app is undefined" if server.nil? + # puts "assets_dir: #{cap.shared_path}/#{Array(cap.fetch(:assets_dir))}" + # puts "local_assets_dir: #{Array(cap.fetch(:local_assets_dir))}" + Array(cap.fetch(:assets_dir)).each do |dir| + system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' #{user}@#{server}:#{cap.shared_path}/#{dir} #{Array(cap.fetch(:local_assets_dir)).join}") end end def local_to_remote(cap) - servers = Capistrano::Configuration.env.send(:servers) - server = servers.detect { |s| s.roles.include?(:app) } - port = server.netssh_options[:port] || 22 - user = server.netssh_options[:user] - [cap.fetch(:assets_dir)].flatten.each do |dir| - system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' ./#{dir} #{user}@#{server}:#{cap.current_path}/#{cap.fetch(:local_assets_dir)}") + raise "server with role app is undefined" if server.nil? + Array(cap.fetch(:assets_dir)).each do |dir| + system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' ./#{dir} #{user}@#{server}:#{cap.current_path}/#{Array(cap.fetch(:local_assets_dir)).join}") end end def to_string(cap) [cap.fetch(:assets_dir)].flatten.join(" ") end + + private + + def server + servers = Capistrano::Configuration.env.send(:servers) + servers.detect { |s| s.roles.include?(:app) } + end + + def port + server.netssh_options[:port] || 22 + end + + def user + server.netssh_options[:user] + end end diff --git a/lib/capistrano-db-tasks/dbtasks.rb b/lib/capistrano-db-tasks/dbtasks.rb index 13e01e3..0ff20b0 100644 --- a/lib/capistrano-db-tasks/dbtasks.rb +++ b/lib/capistrano-db-tasks/dbtasks.rb @@ -8,8 +8,8 @@ set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless fetch(:local_rails_env) set :rails_env, fetch(:stage) || 'production' unless fetch(:rails_env) set :db_local_clean, false unless fetch(:db_local_clean) -set :assets_dir, 'system' unless fetch(:assets_dir) -set :local_assets_dir, 'public' unless fetch(:local_assets_dir) +set :assets_dir, %w(public/system) unless fetch(:assets_dir) +set :local_assets_dir, %w(public) unless fetch(:local_assets_dir) set :skip_data_sync_confirm, (ENV['SKIP_DATA_SYNC_CONFIRM'].to_s.downcase == 'true') set :disallow_pushing, false unless fetch(:disallow_pushing) set :compressor, :gzip unless fetch(:compressor) @@ -56,7 +56,8 @@ desc 'Synchronize your remote assets using local assets' task :sync => 'capistrano_db_tasks:check_can_push' do on roles(:app) do - puts "Assets directories: #{fetch(:assets_dir)}" + puts "Remote assets directories: #{self.shared_path}/#{fetch(:assets_dir).join(', ')}" + puts "Local assets directories: #{fetch(:local_assets_dir).join(', ')}" if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your server assets with local assets") Asset.local_to_remote(self) end @@ -68,7 +69,8 @@ desc 'Synchronize your local assets using remote assets' task :sync do on roles(:app) do - puts "Assets directories: #{fetch(:local_assets_dir)}" + puts "Remote assets directories: #{self.shared_path}/#{fetch(:assets_dir).join(', ')}" + puts "Local assets directories: #{fetch(:local_assets_dir).join(', ')}" if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your local assets with server assets") Asset.remote_to_local(self) end