Class: RSpec::RemoteFixtures::Backend::S3Backend
- Inherits:
-
Object
- Object
- RSpec::RemoteFixtures::Backend::S3Backend
- Defined in:
- lib/rspec/remote_fixtures/backend/s3_backend.rb
Overview
An S3 backend for RemoteFixtures Will only re-upload if the local digest doesn’t match the remote object’s etag
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#s3_bucket ⇒ Object
readonly
Returns the value of attribute s3_bucket.
-
#s3_path ⇒ Object
readonly
Returns the value of attribute s3_path.
-
#s3_prefix ⇒ Object
readonly
Returns the value of attribute s3_prefix.
Instance Method Summary collapse
- #download(remote_path, local_path) ⇒ Object
-
#initialize ⇒ S3Backend
constructor
A new instance of S3Backend.
- #s3 ⇒ Object
- #upload(path, digest) ⇒ Object
Constructor Details
#initialize ⇒ S3Backend
Returns a new instance of S3Backend.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 14 def initialize @s3_path = RemoteFixtures::Config.backend_path raise Error, 'S3 path has not been configured!' unless @s3_path components = s3_path.gsub('s3://', '').split('/') @bucket_name = components[0] @s3_bucket = s3.bucket(bucket_name) @s3_prefix = components[1..].join('/') super end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
12 13 14 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 12 def bucket_name @bucket_name end |
#s3_bucket ⇒ Object (readonly)
Returns the value of attribute s3_bucket.
12 13 14 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 12 def s3_bucket @s3_bucket end |
#s3_path ⇒ Object (readonly)
Returns the value of attribute s3_path.
12 13 14 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 12 def s3_path @s3_path end |
#s3_prefix ⇒ Object (readonly)
Returns the value of attribute s3_prefix.
12 13 14 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 12 def s3_prefix @s3_prefix end |
Instance Method Details
#download(remote_path, local_path) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 38 def download(remote_path, local_path) report_download(remote_path, local_path) if (defined? Timecop) && Timecop.frozen? Timecop.unfreeze do perform_download(remote_path, local_path) end else perform_download(remote_path, local_path) end end |
#s3 ⇒ Object
25 26 27 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 25 def s3 @s3 ||= Aws::S3::Resource.new(client: RemoteFixtures::Config.s3_client) end |
#upload(path, digest) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/rspec/remote_fixtures/backend/s3_backend.rb', line 29 def upload(path, digest) file_name = "#{digest}_#{File.basename(path)}" bucket_path = "#{s3_prefix}/#{file_name}" obj = s3_bucket.object(bucket_path) obj.upload_file(path) unless digest_match?(obj, digest) "s3://#{bucket_name}/#{bucket_path}" end |