Class: Minestrone::Transfer

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

Defined Under Namespace

Classes: SFTPTransferWrapper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {}, &block)
  @direction = direction
  @from      = from
  @to        = to
  @session   = session
  @options   = options
  @callback  = block

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

  prepare_transfer
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



17
18
19
# File 'lib/minestrone/transfer.rb', line 17

def callback
  @callback
end

#directionObject (readonly)

Returns the value of attribute direction.



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

def direction
  @direction
end

#fromObject (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/minestrone/transfer.rb', line 17

def options
  @options
end

#sessionObject (readonly)

Returns the value of attribute session.



17
18
19
# File 'lib/minestrone/transfer.rb', line 17

def session
  @session
end

#toObject (readonly)

Returns the value of attribute to.



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

def to
  @to
end

#transferObject (readonly)

Returns the value of attribute transfer.



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

def transfer
  @transfer
end

#transportObject (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, options = {}, &block)
  new(direction, from, to, session, options, &block).process!
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/minestrone/transfer.rb', line 62

def active?
  transfer.active?
end

#operationObject



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.message})")
    error.host = server

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

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

#sanitized_fromObject



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_toObject



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