Class: S3FileHandler::CSV::Create

Inherits:
BaseOperation show all
Defined in:
lib/s3_file_handler/csv/create.rb

Instance Attribute Summary collapse

Attributes inherited from BaseOperation

#client, #errors

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name, file_key, headers:, client: S3FileHandler.client) ⇒ Create

Returns a new instance of Create.



10
11
12
13
14
15
16
# File 'lib/s3_file_handler/csv/create.rb', line 10

def initialize(bucket_name, file_key, headers:, client: S3FileHandler.client)
  super(client: client)

  @bucket_name = bucket_name
  @file_key = file_key
  @headers = headers
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



8
9
10
# File 'lib/s3_file_handler/csv/create.rb', line 8

def bucket_name
  @bucket_name
end

#file_keyObject (readonly)

Returns the value of attribute file_key.



8
9
10
# File 'lib/s3_file_handler/csv/create.rb', line 8

def file_key
  @file_key
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/s3_file_handler/csv/create.rb', line 8

def headers
  @headers
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
# File 'lib/s3_file_handler/csv/create.rb', line 18

def execute
  csv_string = ::CSV.generate do |csv|
    csv << headers
  end

  S3FileHandler.upload_file(bucket_name, file_key, content: csv_string)
end