Class: S3Archive::S3File

Inherits:
Struct
  • Object
show all
Includes:
Logging
Defined in:
lib/s3archive/s3_file_synchronizer.rb

Overview

A wrapper around a s3 path (bucket, key) with some md5 and a put function

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket

Returns:

  • (Object)

    the current value of bucket



64
65
66
# File 'lib/s3archive/s3_file_synchronizer.rb', line 64

def bucket
  @bucket
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



64
65
66
# File 'lib/s3archive/s3_file_synchronizer.rb', line 64

def key
  @key
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/s3archive/s3_file_synchronizer.rb', line 71

def exists?
  !headers.nil?
end

#md5_hexObject



67
68
69
# File 'lib/s3archive/s3_file_synchronizer.rb', line 67

def md5_hex
  exists? && headers.fetch("etag").tr('"', '')
end

#put(local_file) ⇒ Object



75
76
77
78
79
80
# File 'lib/s3archive/s3_file_synchronizer.rb', line 75

def put(local_file)
  local_file.open do |file|
    logger.info("Putting '#{local_file}' to '#{self}'")
    s3interface.put(bucket, key, file, 'Content-MD5' => local_file.md5_base64)
  end
end

#to_sObject



82
83
84
# File 'lib/s3archive/s3_file_synchronizer.rb', line 82

def to_s
  "s3://#{bucket}/#{key}"
end