Class: CiCache::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/ci-cache/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Storage

Returns a new instance of Storage.



4
5
6
7
8
# File 'lib/ci-cache/storage.rb', line 4

def initialize(context)
  configure_aws
  @s3 = AWS::S3.new
  @context = context
end

Instance Method Details

#download(name, tmp_folder) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ci-cache/storage.rb', line 10

def download(name, tmp_folder)
  target_file = "#{tmp_folder}/#{name}"
  prefixed_name = prefixed_name(name)
  log "Download: #{prefixed_name} ~> #{target_file}"
  object = bucket_object(prefixed_name)
  File.open(target_file, 'wb') do |file|
    object.read do |chunk|
       file.write(chunk)
    end
  end
rescue AWS::S3::Errors::AccessDenied => e
  log "Not found."
end

#upload(name, content) ⇒ Object



24
25
26
27
28
29
# File 'lib/ci-cache/storage.rb', line 24

def upload(name, content)
  prefixed_name = prefixed_name(name)
  log "Upload: #{prefixed_name}"
  object = bucket_object(prefixed_name)
  object.write(content)
end