Class: Drunker::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/drunker/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_dir, config:, logger:) ⇒ Source

Returns a new instance of Source.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/drunker/source.rb', line 5

def initialize(target_dir, config:, logger:)
  timestamp = Time.now.to_i
  s3 = Aws::S3::Resource.new(client: Aws::S3::Client.new(config.aws_client_options))

  @bucket = s3.create_bucket(bucket: "drunker-source-store-#{timestamp}")
  logger.info("Created source bucket: #{bucket.name}")
  @name = "drunker_source_#{timestamp}.zip"
  @target_files = []
  @config = config
  @logger = logger

  set_target_files(target_dir)
  archive(target_dir) do |path|
    bucket.object(name).upload_file(path.to_s)
    logger.info("Uploaded source archive: #{location}")
  end
  @logger = logger
end

Instance Attribute Details

#target_filesObject (readonly)

Returns the value of attribute target_files.



3
4
5
# File 'lib/drunker/source.rb', line 3

def target_files
  @target_files
end

Instance Method Details

#deleteObject



35
36
37
38
# File 'lib/drunker/source.rb', line 35

def delete
  bucket.delete!
  logger.info("Deleted bucket: #{bucket.name}")
end

#locationObject



24
25
26
# File 'lib/drunker/source.rb', line 24

def location
  "#{bucket.name}/#{name}"
end

#to_hObject



28
29
30
31
32
33
# File 'lib/drunker/source.rb', line 28

def to_h
  {
    type: "S3",
    location: location
  }
end