Class: Fulmar::Infrastructure::Model::Transfer::Rsync

Inherits:
Base
  • Object
show all
Defined in:
lib/fulmar/infrastructure/model/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

config_hash, #prepare, #publish, #test_config

Constructor Details

#initialize(config) ⇒ Rsync

Returns a new instance of Rsync.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fulmar/infrastructure/model/transfer/rsync.rb', line 22

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

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

  raise 'Hostname not set. Cannot initialize sync.' if @config[:hostname].nil? || @config[:hostname].empty?

  super(@config)
end

Instance Method Details

#release_pathString

Gets the absolute release path

Returns:

  • (String)

    the release directory



54
55
56
# File 'lib/fulmar/infrastructure/model/transfer/rsync.rb', line 54

def release_path
  @config[:remote_path]
end

#rsync_commandObject

Build the rsync command from the given options



41
42
43
44
45
46
47
48
49
50
# File 'lib/fulmar/infrastructure/model/transfer/rsync.rb', line 41

def rsync_command
  if @config[:rsync][:direction] == 'up'
    from = absolute_path(@config[:local_path])
    to = @config.ssh_user_and_host + ':' + @config[:remote_path]
  else
    from = @config.ssh_user_and_host + ':' + @config[:remote_path]
    to = absolute_path(@config[:local_path])
  end
  "rsync #{rsync_command_options.join(' ')} '#{from}/' '#{to}'"
end

#transferObject



35
36
37
38
# File 'lib/fulmar/infrastructure/model/transfer/rsync.rb', line 35

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