Class: Capistrano::Transfer
- Inherits:
-
Object
- Object
- Capistrano::Transfer
- Includes:
- Processable
- Defined in:
- lib/capistrano/transfer.rb
Defined Under Namespace
Classes: SFTPTransferWrapper
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sessions ⇒ Object
readonly
Returns the value of attribute sessions.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#transfers ⇒ Object
readonly
Returns the value of attribute transfers.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(direction, from, to, sessions, options = {}, &block) ⇒ Transfer
constructor
A new instance of Transfer.
- #operation ⇒ Object
- #process! ⇒ Object
- #sanitized_from ⇒ Object
- #sanitized_to ⇒ Object
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.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/capistrano/transfer.rb', line 26 def initialize(direction, from, to, sessions, ={}, &block) @direction = direction @from = from @to = to @sessions = sessions @options = @callback = block @transport = .fetch(:via, :sftp) @logger = .delete(:logger) @session_map = {} prepare_transfers end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
16 17 18 |
# File 'lib/capistrano/transfer.rb', line 16 def callback @callback end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
19 20 21 |
# File 'lib/capistrano/transfer.rb', line 19 def direction @direction end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
20 21 22 |
# File 'lib/capistrano/transfer.rb', line 20 def from @from end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
23 24 25 |
# File 'lib/capistrano/transfer.rb', line 23 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/capistrano/transfer.rb', line 15 def @options end |
#sessions ⇒ Object (readonly)
Returns the value of attribute sessions.
14 15 16 |
# File 'lib/capistrano/transfer.rb', line 14 def sessions @sessions end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
21 22 23 |
# File 'lib/capistrano/transfer.rb', line 21 def to @to end |
#transfers ⇒ Object (readonly)
Returns the value of attribute transfers.
24 25 26 |
# File 'lib/capistrano/transfer.rb', line 24 def transfers @transfers end |
#transport ⇒ Object (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, ={}, &block) new(direction, from, to, sessions, , &block).process! end |
Instance Method Details
#active? ⇒ Boolean
70 71 72 |
# File 'lib/capistrano/transfer.rb', line 70 def active? transfers.any? { |transfer| transfer.active? } end |
#operation ⇒ Object
74 75 76 |
# File 'lib/capistrano/transfer.rb', line 74 def operation "#{direction}load" end |
#process! ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/capistrano/transfer.rb', line 42 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 failed = transfers.select { |txfr| txfr[:failed] } if failed.any? hosts = failed.map { |txfr| txfr[:server] } errors = failed.map { |txfr| "#{txfr[:error]} (#{txfr[:error].})" }.uniq.join(", ") error = TransferError.new("#{operation} via #{transport} failed on #{hosts.join(',')}: #{errors}") error.hosts = hosts logger.important(error.) if logger raise error end logger.debug "#{transport} #{operation} complete" if logger self end |
#sanitized_from ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/capistrano/transfer.rb', line 78 def sanitized_from if from.responds_to?(:read) "#<#{from.class}>" else from end end |
#sanitized_to ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/capistrano/transfer.rb', line 86 def sanitized_to if to.responds_to?(:read) "#<#{to.class}>" else to end end |