Class: Prebundler::S3Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/prebundler/s3_backend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ S3Backend

Returns a new instance of S3Backend.



7
8
9
10
11
12
# File 'lib/prebundler/s3_backend.rb', line 7

def initialize(options = {})
  @access_key_id = options.fetch(:access_key_id)
  @secret_access_key = options.fetch(:secret_access_key)
  @bucket = options.fetch(:bucket)
  @region = options.fetch(:region)
end

Instance Attribute Details

#access_key_idObject (readonly)

Returns the value of attribute access_key_id.



5
6
7
# File 'lib/prebundler/s3_backend.rb', line 5

def access_key_id
  @access_key_id
end

#bucketObject (readonly)

Returns the value of attribute bucket.



5
6
7
# File 'lib/prebundler/s3_backend.rb', line 5

def bucket
  @bucket
end

#regionObject (readonly)

Returns the value of attribute region.



5
6
7
# File 'lib/prebundler/s3_backend.rb', line 5

def region
  @region
end

#secret_access_keyObject (readonly)

Returns the value of attribute secret_access_key.



5
6
7
# File 'lib/prebundler/s3_backend.rb', line 5

def secret_access_key
  @secret_access_key
end

Instance Method Details

#docker_flagsObject



56
57
58
# File 'lib/prebundler/s3_backend.rb', line 56

def docker_flags
  []
end

#list_filesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/prebundler/s3_backend.rb', line 28

def list_files
  truncated = true
  continuation_token = nil
  files = []
  base_options = {
    bucket: bucket,
    prefix: "#{Bundler.local_platform.to_s}/#{Gem.extension_api_version.to_s}"
  }

  while truncated
    options = if continuation_token
      base_options.merge(continuation_token: continuation_token)
    else
      base_options
    end

    response = client.list_objects_v2(options)
    truncated = response.is_truncated
    continuation_token = response.continuation_token

    response.contents.each do |file|
      files << file.key
    end
  end

  files
end

#retrieve_file(source_file, dest_file) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/prebundler/s3_backend.rb', line 20

def retrieve_file(source_file, dest_file)
  client.get_object(
    bucket: bucket,
    key: source_file,
    response_target: dest_file
  )
end

#store_file(source_file, dest_file) ⇒ Object



14
15
16
17
18
# File 'lib/prebundler/s3_backend.rb', line 14

def store_file(source_file, dest_file)
  File.open(source_file) do |io|
    client.put_object(bucket: bucket, key: dest_file, body: io)
  end
end