Class: Egads::S3Tarball

Inherits:
Object
  • Object
show all
Defined in:
lib/egads/s3_tarball.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sha, options = {}) ⇒ S3Tarball

Returns a new instance of S3Tarball.



4
5
6
7
8
# File 'lib/egads/s3_tarball.rb', line 4

def initialize(sha, options = {})
  @sha    = sha
  @remote = options[:remote]
  @seed   = options[:seed]
end

Instance Attribute Details

#remoteObject (readonly)

Returns the value of attribute remote.



3
4
5
# File 'lib/egads/s3_tarball.rb', line 3

def remote
  @remote
end

#seedObject (readonly)

Returns the value of attribute seed.



3
4
5
# File 'lib/egads/s3_tarball.rb', line 3

def seed
  @seed
end

#shaObject (readonly)

Returns the value of attribute sha.



3
4
5
# File 'lib/egads/s3_tarball.rb', line 3

def sha
  @sha
end

Instance Method Details

#bucketObject



41
42
43
# File 'lib/egads/s3_tarball.rb', line 41

def bucket
  config.s3_bucket
end

#configObject



10
11
12
# File 'lib/egads/s3_tarball.rb', line 10

def config
  remote ? RemoteConfig : Config
end

#download(file) ⇒ Object

Write the S3 object’s contents to a local file



37
38
39
# File 'lib/egads/s3_tarball.rb', line 37

def download(file)
  bucket.object(key).get(response_target: file)
end

#exists?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/egads/s3_tarball.rb', line 22

def exists?
  bucket.object(key).exists?
end

#keyObject



14
15
16
17
18
19
20
# File 'lib/egads/s3_tarball.rb', line 14

def key
  [
    config.s3_prefix,
    seed ? 'seeds' : nil,
    "#{sha}.tar.gz"
  ].compact * '/'
end

#local_tar_pathObject



26
27
28
# File 'lib/egads/s3_tarball.rb', line 26

def local_tar_path
  "tmp/#{sha}.tar.gz"
end

#upload(path = local_tar_path) ⇒ Object



30
31
32
33
34
# File 'lib/egads/s3_tarball.rb', line 30

def upload(path=local_tar_path)
  File.open(path) {|f|
    bucket.put_object(key: key, body: f)
  }
end