Class: SmartS3Sync::FileTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_s3_sync/file_target.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(digest, remote_filename, size) ⇒ FileTarget

Returns a new instance of FileTarget.



8
9
10
11
12
13
14
# File 'lib/smart_s3_sync/file_target.rb', line 8

def initialize(digest, remote_filename, size)
  @digest          = digest
  @size            = size
  @remote_filename = remote_filename
  @local_source    = nil
  @destinations    = []
end

Instance Attribute Details

#destinationsObject (readonly)

Returns the value of attribute destinations.



6
7
8
# File 'lib/smart_s3_sync/file_target.rb', line 6

def destinations
  @destinations
end

#digestObject (readonly)

Returns the value of attribute digest.



6
7
8
# File 'lib/smart_s3_sync/file_target.rb', line 6

def digest
  @digest
end

#local_sourceObject (readonly)

Returns the value of attribute local_source.



6
7
8
# File 'lib/smart_s3_sync/file_target.rb', line 6

def local_source
  @local_source
end

#remote_filenameObject (readonly)

Returns the value of attribute remote_filename.



6
7
8
# File 'lib/smart_s3_sync/file_target.rb', line 6

def remote_filename
  @remote_filename
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/smart_s3_sync/file_target.rb', line 6

def size
  @size
end

Instance Method Details

#add_destination(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/smart_s3_sync/file_target.rb', line 16

def add_destination(file)
  unless destinations.include?(file)
    # If we already have a local file with the right checksum,
    # we don't add it to the list of destinations and instead
    # mark it as a local source.
    if File.exists?(file) && file_hash(file) == digest.to_s
      add_local_source(file)
    else
      destinations.push(file)
    end
  end
end

#copy!(fog_dir, sync_options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/smart_s3_sync/file_target.rb', line 29

def copy!(fog_dir, sync_options={})
  # If every copy in the cloud is already present, the
  # number of destinations will be 0 - there is no work
  # left to do.
  if destinations.length > 0
    if local_source.nil?     # we prefer to not have to download
      copy_from_fog(fog_dir, sync_options)
    else
      copy_from_local(local_source, sync_options)
    end
  end
end