Class: DB2S3::S3Store
- Inherits:
-
Object
- Object
- DB2S3::S3Store
- Defined in:
- lib/db2s3.rb
Instance Method Summary collapse
- #delete(file_name) ⇒ Object
- #ensure_connected ⇒ Object
- #fetch(file_name) ⇒ Object
-
#initialize ⇒ S3Store
constructor
A new instance of S3Store.
- #list ⇒ Object
- #store(file_name, file) ⇒ Object
Constructor Details
#initialize ⇒ S3Store
Returns a new instance of S3Store.
117 118 119 |
# File 'lib/db2s3.rb', line 117 def initialize @connected = false end |
Instance Method Details
#delete(file_name) ⇒ Object
151 152 153 154 155 |
# File 'lib/db2s3.rb', line 151 def delete(file_name) if object = AWS::S3::S3Object.find(file_name, bucket) object.delete end end |
#ensure_connected ⇒ Object
121 122 123 124 125 126 |
# File 'lib/db2s3.rb', line 121 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
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/db2s3.rb', line 133 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 |
#list ⇒ Object
146 147 148 149 |
# File 'lib/db2s3.rb', line 146 def list ensure_connected AWS::S3::Bucket.find(bucket).objects.collect {|x| x.path } end |
#store(file_name, file) ⇒ Object
128 129 130 131 |
# File 'lib/db2s3.rb', line 128 def store(file_name, file) ensure_connected AWS::S3::S3Object.store(file_name, file, bucket) end |