Class: DbBlaster::S3KeyBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/db_blaster/s3_key_builder.rb

Overview

Builds the key to be used for the uploaded S3 Object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_table_name, batch_start_time) ⇒ S3KeyBuilder

Returns a new instance of S3KeyBuilder.



8
9
10
11
# File 'lib/db_blaster/s3_key_builder.rb', line 8

def initialize(source_table_name, batch_start_time)
  @source_table_name = source_table_name
  @batch_start_time = batch_start_time
end

Instance Attribute Details

#batch_start_timeObject (readonly)

Returns the value of attribute batch_start_time.



6
7
8
# File 'lib/db_blaster/s3_key_builder.rb', line 6

def batch_start_time
  @batch_start_time
end

#source_table_nameObject (readonly)

Returns the value of attribute source_table_name.



6
7
8
# File 'lib/db_blaster/s3_key_builder.rb', line 6

def source_table_name
  @source_table_name
end

Class Method Details

.build(source_table_name:, batch_start_time:) ⇒ Object



13
14
15
# File 'lib/db_blaster/s3_key_builder.rb', line 13

def self.build(source_table_name:, batch_start_time:)
  new(source_table_name, batch_start_time).build
end

Instance Method Details

#buildObject



17
18
19
20
21
22
23
# File 'lib/db_blaster/s3_key_builder.rb', line 17

def build
  key = starting_key
  substitutions.each do |replace, value|
    key = key.gsub(replace, value)
  end
  key
end

#starting_keyObject



36
37
38
# File 'lib/db_blaster/s3_key_builder.rb', line 36

def starting_key
  DbBlaster.configuration.s3_key.presence || Configuration::DEFAULT_S3_KEY
end

#substitutionsObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/db_blaster/s3_key_builder.rb', line 25

def substitutions
  date_time = DateTime.now.utc.strftime(DbBlaster::Configuration::DEFAULT_DATETIME_FORMAT)
  date, time = batch_start_time.split('T')
  { '<batch_date_time>' => batch_start_time,
    '<batch_date>' => date,
    '<batch_time>' => time,
    '<date_time>' => date_time,
    '<uuid>' => SecureRandom.uuid,
    '<table_name>' => source_table_name }
end