Class: Simmer::Externals::AwsFileSystem

Inherits:
FileSystem
  • Object
show all
Defined in:
lib/simmer/externals/aws_file_system.rb

Overview

Provides the implementation for using AWS S3 as a destination file store.

Instance Method Summary collapse

Constructor Details

#initialize(aws_s3_client, bucket, encryption, files_dir) ⇒ AwsFileSystem

Returns a new instance of AwsFileSystem.

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/simmer/externals/aws_file_system.rb', line 16

def initialize(aws_s3_client, bucket, encryption, files_dir)
  raise ArgumentError, 'aws_s3_client is required' unless aws_s3_client
  raise ArgumentError, 'bucket is required'        if bucket.to_s.empty?

  super(bucket)

  @aws_s3_client = aws_s3_client
  @encryption    = encryption
  @files_dir     = files_dir

  freeze
end

Instance Method Details

#clean!Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/simmer/externals/aws_file_system.rb', line 39

def clean!
  response    = aws_s3_client.list_objects(bucket: root)
  objects     = response.contents
  keys        = objects.map(&:key)
  delete_keys = keys.map { |key| { key: key } }

  return 0 if objects.length.zero?

  aws_s3_client.delete_objects(
    bucket: root,
    delete: {
      objects: delete_keys
    }
  )

  delete_keys.length
end

#write!(input_files) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/simmer/externals/aws_file_system.rb', line 29

def write!(input_files)
  input_files.each do |input_file|
    src = File.join(files_dir, input_file.src)

    write_single(input_file.dest, src)
  end

  input_files.length
end