Class: DB2S3::S3Store

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

Instance Method Summary collapse

Constructor Details

#initializeS3Store

Returns a new instance of S3Store.



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

def initialize
  @connected = false
end

Instance Method Details

#ensure_connectedObject



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

def ensure_connected
  return if @connected
  AWS::S3::Base.establish_connection!(DB2S3::Config::S3.slice(:access_key_id, :secret_access_key).merge(:use_ssl => true))
  AWS::S3::Bucket.create(bucket)
  @connected = true
end

#fetch(file_name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/db2s3.rb', line 87

def fetch(file_name)
  ensure_connected
  AWS::S3::S3Object.find(file_name, bucket)
  
  file = Tempfile.new("dump")
  open(file.path, 'w') do |f|
    AWS::S3::S3Object.stream(file_name, bucket) do |chunk|
      f.write chunk
    end
  end
  file
end

#store(file_name, file) ⇒ Object



82
83
84
85
# File 'lib/db2s3.rb', line 82

def store(file_name, file)
  ensure_connected
  AWS::S3::S3Object.store(file_name, file, bucket)
end