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.
-
#silent ⇒ Object
readonly
Returns the value of attribute silent.
-
#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.
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, ={}, &block) @direction = direction @from = from @to = to @sessions = sessions proc = .delete(:proc) @options = @callback = block @transport = .fetch(:via, :sftp) @logger = .delete(:logger) @silent = .delete(:silent) @session_map = {} prepare_transfers(proc) 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 |
#silent ⇒ Object (readonly)
Returns the value of attribute silent.
25 26 27 |
# File 'lib/capistrano/transfer.rb', line 25 def silent @silent 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
75 76 77 |
# File 'lib/capistrano/transfer.rb', line 75 def active? transfers.any? { |transfer| transfer.active? } end |
#operation ⇒ Object
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].})" }.uniq.join(", ") error = TransferError.new("#{operation} via #{transport} failed on #{hosts.join(',')}: #{errors}") error.hosts = hosts logger.important(error.) if logger raise error end end logger.debug "#{transport} #{operation} complete" if logger && !silent self end |
#sanitized_from ⇒ Object
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_to ⇒ Object
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 |