Class: CarthageCache::Repository
- Inherits:
-
Object
- Object
- CarthageCache::Repository
- Defined in:
- lib/carthage_cache/repository.rb
Constant Summary collapse
- DEFAULT_BUCKET_NAME =
"carthage-cache"
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #archive_exist?(archive_filename) ⇒ Boolean
- #download(archive_filename, destination_path) ⇒ Object
-
#initialize(bucket_name, client_options = {}) ⇒ Repository
constructor
A new instance of Repository.
- #upload(archive_filename, archive_path) ⇒ Object
Constructor Details
#initialize(bucket_name, client_options = {}) ⇒ Repository
Returns a new instance of Repository.
12 13 14 15 |
# File 'lib/carthage_cache/repository.rb', line 12 def initialize(bucket_name, = {}) @client = ::Aws::S3::Client.new() @bucket_name = bucket_name || DEFAULT_BUCKET_NAME end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
10 11 12 |
# File 'lib/carthage_cache/repository.rb', line 10 def bucket_name @bucket_name end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/carthage_cache/repository.rb', line 9 def client @client end |
Instance Method Details
#archive_exist?(archive_filename) ⇒ Boolean
17 18 19 |
# File 'lib/carthage_cache/repository.rb', line 17 def archive_exist?(archive_filename) ::Aws::S3::Object.new(bucket_name, archive_filename, client: client).exists? end |
#download(archive_filename, destination_path) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/carthage_cache/repository.rb', line 21 def download(archive_filename, destination_path) resp = client.get_object( response_target: destination_path, bucket: bucket_name, key: archive_filename) end |
#upload(archive_filename, archive_path) ⇒ Object
28 29 30 31 32 |
# File 'lib/carthage_cache/repository.rb', line 28 def upload(archive_filename, archive_path) File.open(archive_path, 'rb') do |file| client.put_object(bucket: bucket_name, key: archive_filename, body: file) end end |