Class: Minestrone::Transfer
- Inherits:
-
Object
- Object
- Minestrone::Transfer
- Includes:
- Processable
- Defined in:
- lib/minestrone/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.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#transfer ⇒ Object
readonly
Returns the value of attribute transfer.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(direction, from, to, session, options = {}, &block) ⇒ Transfer
constructor
A new instance of Transfer.
- #operation ⇒ Object
- #process! ⇒ Object
- #sanitized_from ⇒ Object
- #sanitized_to ⇒ Object
Methods included from Processable
#ensure_session, #process_iteration
Constructor Details
#initialize(direction, from, to, session, options = {}, &block) ⇒ Transfer
Returns a new instance of Transfer.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/minestrone/transfer.rb', line 21 def initialize(direction, from, to, session, = {}, &block) @direction = direction @from = from @to = to @session = session @options = @callback = block @transport = .fetch(:via, :sftp) @logger = .delete(:logger) prepare_transfer end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
17 18 19 |
# File 'lib/minestrone/transfer.rb', line 17 def callback @callback end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
18 19 20 |
# File 'lib/minestrone/transfer.rb', line 18 def direction @direction end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
18 19 20 |
# File 'lib/minestrone/transfer.rb', line 18 def from @from end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
19 20 21 |
# File 'lib/minestrone/transfer.rb', line 19 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/minestrone/transfer.rb', line 17 def @options end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
17 18 19 |
# File 'lib/minestrone/transfer.rb', line 17 def session @session end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
18 19 20 |
# File 'lib/minestrone/transfer.rb', line 18 def to @to end |
#transfer ⇒ Object (readonly)
Returns the value of attribute transfer.
19 20 21 |
# File 'lib/minestrone/transfer.rb', line 19 def transfer @transfer end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
18 19 20 |
# File 'lib/minestrone/transfer.rb', line 18 def transport @transport end |
Class Method Details
.process(direction, from, to, session, options = {}, &block) ⇒ Object
13 14 15 |
# File 'lib/minestrone/transfer.rb', line 13 def self.process(direction, from, to, session, = {}, &block) new(direction, from, to, session, , &block).process! end |
Instance Method Details
#active? ⇒ Boolean
62 63 64 |
# File 'lib/minestrone/transfer.rb', line 62 def active? transfer.active? end |
#operation ⇒ Object
66 67 68 |
# File 'lib/minestrone/transfer.rb', line 66 def operation "#{direction}load" end |
#process! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/minestrone/transfer.rb', line 35 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 if transfer[:failed] server = transfer[:server] transfer_error = transfer[:error] error = TransferError.new("#{operation} via #{transport} failed on #{server}: #{transfer_error} (#{transfer_error.})") error.host = server logger.important(error.) if logger raise error end logger.debug "#{transport} #{operation} complete" if logger self end |
#sanitized_from ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/minestrone/transfer.rb', line 70 def sanitized_from if from.responds_to?(:read) "#<#{from.class}>" else from end end |
#sanitized_to ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/minestrone/transfer.rb', line 78 def sanitized_to if to.responds_to?(:read) "#<#{to.class}>" else to end end |