Class: Snapshooter::Storage::S3

Inherits:
Base
  • Object
show all
Defined in:
lib/snapshooter/storage/s3.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #restore, #snapshot!

Methods included from Log

#with_log

Constructor Details

This class inherits a constructor from Snapshooter::Base

Instance Method Details

#get(filename, &block) ⇒ Object



30
31
32
33
34
35
# File 'lib/snapshooter/storage/s3.rb', line 30

def get(filename, &block)
  directory = connection.directories.get(bucket)
  file      = directory.files.get(filename)

  with_tempfile file.body, &block
end

#save(filename, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/snapshooter/storage/s3.rb', line 6

def save(filename, &block)
  with_log("Save #{bucket}/#{filename} to S3") do
    directory = connection.directories.create(
      :key    => bucket,
      :public => false
    )

    file = Tempfile.new("snapshooter_s3_storage")
    file.close

    begin
      yield file.path

      directory.files.create(
        :key    => filename,
        :body   => File.open(file.path),
        :public => false
      )
    ensure
      file.unlink
    end
  end
end