Class: DB2S3::S3Store
- Inherits:
-
Object
- Object
- DB2S3::S3Store
- Defined in:
- lib/db2s3.rb
Instance Method Summary collapse
- #ensure_connected ⇒ Object
- #fetch(file_name) ⇒ Object
-
#initialize ⇒ S3Store
constructor
A new instance of S3Store.
- #store(file_name, file) ⇒ Object
Constructor Details
#initialize ⇒ S3Store
Returns a new instance of S3Store.
81 82 83 |
# File 'lib/db2s3.rb', line 81 def initialize @connected = false end |
Instance Method Details
#ensure_connected ⇒ Object
85 86 87 88 89 90 |
# File 'lib/db2s3.rb', line 85 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
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/db2s3.rb', line 97 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
92 93 94 95 |
# File 'lib/db2s3.rb', line 92 def store(file_name, file) ensure_connected AWS::S3::S3Object.store(file_name, file, bucket) end |