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.
71 72 73 |
# File 'lib/db2s3.rb', line 71 def initialize @connected = false end |
Instance Method Details
#ensure_connected ⇒ Object
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 |