Class: Fulmar::Infrastructure::Service::Transfer::Rsync

Inherits:
Base
  • Object
show all
Defined in:
lib/fulmar/infrastructure/service/transfer/rsync.rb

Overview

Implements the rsync transfer

Constant Summary collapse

DEFAULT_CONFIG =
{
  rsync: {
    exclude: nil,
    exclude_file: nil,
    chown: nil,
    chmod: nil,
    delete: true,
    direction: 'up'
  }
}

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#prepare, #publish, #test_config

Constructor Details

#initialize(config) ⇒ Rsync

Returns a new instance of Rsync.



21
22
23
24
25
26
27
28
29
# File 'lib/fulmar/infrastructure/service/transfer/rsync.rb', line 21

def initialize(config)
  @config = DEFAULT_CONFIG.deep_merge(config)

  if @config[:rsync][:exclude_file].blank? && File.exist?(@config[:local_path] + '/.rsyncignore')
    @config[:rsync][:exclude_file] = @config[:local_path] + '/.rsyncignore'
  end

  super(@config)
end

Instance Method Details

#rsync_commandObject

Build the rsync command from the given options



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fulmar/infrastructure/service/transfer/rsync.rb', line 37

def rsync_command
  if @config[:rsync][:direction] == 'up'
    from = @config[:local_path]
    to = ssh_user_and_host + ':' + @config[:remote_path]
  else
    from = ssh_user_and_host + ':' + @config[:remote_path]
    to = @config[:local_path]
  end

  "rsync #{rsync_command_options.join(' ')} '#{from}/' '#{to}'"
end

#transferObject



31
32
33
34
# File 'lib/fulmar/infrastructure/service/transfer/rsync.rb', line 31

def transfer
  prepare unless @prepared
  @local_shell.run rsync_command
end