Class: CarthageCacheRes::AWSRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/carthage_cache_res/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name, client_options = {}) ⇒ AWSRepository

Returns a new instance of AWSRepository.



10
11
12
13
# File 'lib/carthage_cache_res/repository.rb', line 10

def initialize(bucket_name, client_options = {})
  @client = ::Aws::S3::Client.new(client_options)
  @bucket_name = bucket_name
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



8
9
10
# File 'lib/carthage_cache_res/repository.rb', line 8

def bucket_name
  @bucket_name
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/carthage_cache_res/repository.rb', line 7

def client
  @client
end

Instance Method Details

#archive_exist?(archive_filename) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/carthage_cache_res/repository.rb', line 15

def archive_exist?(archive_filename)
  ::Aws::S3::Object.new(bucket_name, archive_filename, client: client).exists?
end

#download(archive_filename, destination_path) ⇒ Object



19
20
21
22
23
24
# File 'lib/carthage_cache_res/repository.rb', line 19

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



26
27
28
29
30
# File 'lib/carthage_cache_res/repository.rb', line 26

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