Class: CloudFilesTransfer::Transfer

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_files_transfer/transfer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, destination, path, args = {}) ⇒ Transfer

Returns a new instance of Transfer.



6
7
8
9
10
# File 'lib/cloud_files_transfer/transfer.rb', line 6

def initialize(origin, destination, path, args={})
  @origin = origin
  @destination = destination
  @path = path
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



4
5
6
# File 'lib/cloud_files_transfer/transfer.rb', line 4

def destination
  @destination
end

#originObject

Returns the value of attribute origin.



4
5
6
# File 'lib/cloud_files_transfer/transfer.rb', line 4

def origin
  @origin
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/cloud_files_transfer/transfer.rb', line 4

def path
  @path
end

Class Method Details

.copy!(origin, destination, path, args = {}) ⇒ Object



12
13
14
15
# File 'lib/cloud_files_transfer/transfer.rb', line 12

def self.copy!(origin, destination, path, args={})
  return if destination.object_exists?(path)
  new(origin, destination, path, args).copy
end

Instance Method Details

#copyObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cloud_files_transfer/transfer.rb', line 17

def copy
  retries = 0
  puts "Saving #{path}"
  begin
    origin_object = origin.object(path)
    desintation_object = destination.create_object(path)
    desintation_object.write(origin_object.data)
  rescue Exception
    retries = retries + 1
    unless retries > 5
      puts "#{path} failed. Retry"
      retry
    else
      puts "#{path} failed."
    end
  end
end