class Capistrano::SCM::Rsync

Public Instance Methods

copy_local_to_remote(role) click to toggle source
# File lib/capistrano/scm/rsync.rb, line 35
def copy_local_to_remote(role)
  if dry_run?
    puts "Would execute: #{rsync_command(role).inspect}"
    return
  end

  RakeFileUtils.sh(*rsync_command(role))
end
create_release() click to toggle source
# File lib/capistrano/scm/rsync.rb, line 44
def create_release
  # Skip copying if we've already synced straight to the release directory.
  return unless remote_cache

  copy = [
    'rsync',
    fetch(:rsync_options)[:args][:cache_to_release],
    File.join(remote_directory, '/').shellescape,
    '.'
  ].flatten

  backend.execute(*copy)
end
define_tasks() click to toggle source
# File lib/capistrano/scm/rsync.rb, line 26
def define_tasks
  eval_rakefile(File.expand_path('../tasks/rsync.rake', __FILE__))
end
register_hooks() click to toggle source
# File lib/capistrano/scm/rsync.rb, line 30
def register_hooks
  after 'deploy:new_release_path', 'rsync:create_release'
  before 'deploy:set_current_revision', 'rsync:set_current_revision'
end
set_defaults() click to toggle source
# File lib/capistrano/scm/rsync.rb, line 6
def set_defaults
  set_if_empty :rsync_options,
               # The local directory to be copied to the server.
               source: 'app',
               # The cache directory on the server that receives files
               # from the source directory. Relative to shared_path or
               # an absolute path.
               # Saves you rsyncing your whole app folder each time. If
               # set to nil Capistrano::SCM::Rsync will sync directly to
               # the release_path.
               cache: 'cache',
               # Arguments passed to rsync when...
               args: {
                 # ...copying the local directory to the server.
                 local_to_remote: [],
                 # ...copying the cache directory to the release_path.
                 cache_to_release: %w(--archive --acls --xattrs)
               }
end

Private Instance Methods

remote_cache() click to toggle source
# File lib/capistrano/scm/rsync.rb, line 76
def remote_cache
  fetch(:rsync_options)[:cache]
end
remote_directory() click to toggle source
# File lib/capistrano/scm/rsync.rb, line 80
def remote_directory
  return release_path unless remote_cache

  cache = remote_cache
  cache = File.join(shared_path, cache) if cache && cache !~ %r{^/}
  cache
end
remote_user(role) click to toggle source
# File lib/capistrano/scm/rsync.rb, line 66
def remote_user(role)
  user = if role.user
           role.user
         elsif fetch(:ssh_options)[:user]
           fetch(:ssh_options)[:user]
         end

  "#{user}@" unless user.nil?
end
rsync_command(role) click to toggle source
# File lib/capistrano/scm/rsync.rb, line 60
def rsync_command(role)
  rsync = %w(rsync) + fetch(:rsync_options)[:args][:local_to_remote]
  rsync << File.join(fetch(:rsync_options)[:source], '/')
  rsync << "#{remote_user(role)}#{role.hostname}:#{remote_directory}"
end