Class: Capistrano::Transfer

Inherits:
Object
  • Object
show all
Includes:
Processable
Defined in:
lib/capistrano/transfer.rb

Defined Under Namespace

Classes: SFTPTransferWrapper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Processable

#ensure_each_session, #process_iteration

Constructor Details

#initialize(direction, from, to, sessions, options = {}, &block) ⇒ Transfer

Returns a new instance of Transfer.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/capistrano/transfer.rb', line 27

def initialize(direction, from, to, sessions, options={}, &block)
  @direction = direction
  @from      = from
  @to        = to
  @sessions  = sessions
  proc       = options.delete(:proc)
  @options   = options
  @callback  = block

  @transport = options.fetch(:via, :sftp)
  @logger    = options.delete(:logger)
  @silent    = options.delete(:silent)

  @session_map = {}

  prepare_transfers(proc)
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



16
17
18
# File 'lib/capistrano/transfer.rb', line 16

def callback
  @callback
end

#directionObject (readonly)

Returns the value of attribute direction.



19
20
21
# File 'lib/capistrano/transfer.rb', line 19

def direction
  @direction
end

#fromObject (readonly)

Returns the value of attribute from.



20
21
22
# File 'lib/capistrano/transfer.rb', line 20

def from
  @from
end

#loggerObject (readonly)

Returns the value of attribute logger.



23
24
25
# File 'lib/capistrano/transfer.rb', line 23

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/capistrano/transfer.rb', line 15

def options
  @options
end

#sessionsObject (readonly)

Returns the value of attribute sessions.



14
15
16
# File 'lib/capistrano/transfer.rb', line 14

def sessions
  @sessions
end

#silentObject (readonly)

Returns the value of attribute silent.



25
26
27
# File 'lib/capistrano/transfer.rb', line 25

def silent
  @silent
end

#toObject (readonly)

Returns the value of attribute to.



21
22
23
# File 'lib/capistrano/transfer.rb', line 21

def to
  @to
end

#transfersObject (readonly)

Returns the value of attribute transfers.



24
25
26
# File 'lib/capistrano/transfer.rb', line 24

def transfers
  @transfers
end

#transportObject (readonly)

Returns the value of attribute transport.



18
19
20
# File 'lib/capistrano/transfer.rb', line 18

def transport
  @transport
end

Class Method Details

.process(direction, from, to, sessions, options = {}, &block) ⇒ Object



10
11
12
# File 'lib/capistrano/transfer.rb', line 10

def self.process(direction, from, to, sessions, options={}, &block)
  new(direction, from, to, sessions, options, &block).process!
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/capistrano/transfer.rb', line 75

def active?
  transfers.any? { |transfer| transfer.active? }
end

#operationObject



79
80
81
# File 'lib/capistrano/transfer.rb', line 79

def operation
  "#{direction}load"
end

#process!Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/capistrano/transfer.rb', line 45

def process!
  loop do
    begin
      break unless process_iteration { active? }
    rescue Exception => error
      if error.respond_to?(:session)
        handle_error(error)
      else
        raise
      end
    end
  end

  unless silent
    failed = transfers.select { |txfr| txfr[:failed] }
    if failed.any?
      hosts = failed.map { |txfr| txfr[:server] }
      errors = failed.map { |txfr| "#{txfr[:error]} (#{txfr[:error].message})" }.uniq.join(", ")
      error = TransferError.new("#{operation} via #{transport} failed on #{hosts.join(',')}: #{errors}")
      error.hosts = hosts

      logger.important(error.message) if logger
      raise error
    end
  end

  logger.debug "#{transport} #{operation} complete" if logger && !silent
  self
end

#sanitized_fromObject



83
84
85
86
87
88
89
# File 'lib/capistrano/transfer.rb', line 83

def sanitized_from
  if from.responds_to?(:read)
    "#<#{from.class}>"
  else
    from
  end
end

#sanitized_toObject



91
92
93
94
95
96
97
# File 'lib/capistrano/transfer.rb', line 91

def sanitized_to
  if to.responds_to?(:read)
    "#<#{to.class}>"
  else
    to
  end
end