Class: S3FileHandler::CSV::AppendRow
- Inherits:
-
BaseOperation
- Object
- BaseOperation
- S3FileHandler::CSV::AppendRow
- Defined in:
- lib/s3_file_handler/csv/append_row.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#file_key ⇒ Object
readonly
Returns the value of attribute file_key.
-
#row_data ⇒ Object
readonly
Returns the value of attribute row_data.
Attributes inherited from BaseOperation
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(bucket_name, file_key, row_data:, client: S3FileHandler.client) ⇒ AppendRow
constructor
A new instance of AppendRow.
Constructor Details
#initialize(bucket_name, file_key, row_data:, client: S3FileHandler.client) ⇒ AppendRow
Returns a new instance of AppendRow.
10 11 12 13 14 15 16 |
# File 'lib/s3_file_handler/csv/append_row.rb', line 10 def initialize(bucket_name, file_key, row_data:, client: S3FileHandler.client) super(client: client) @bucket_name = bucket_name @file_key = file_key @row_data = row_data end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
8 9 10 |
# File 'lib/s3_file_handler/csv/append_row.rb', line 8 def bucket_name @bucket_name end |
#file_key ⇒ Object (readonly)
Returns the value of attribute file_key.
8 9 10 |
# File 'lib/s3_file_handler/csv/append_row.rb', line 8 def file_key @file_key end |
#row_data ⇒ Object (readonly)
Returns the value of attribute row_data.
8 9 10 |
# File 'lib/s3_file_handler/csv/append_row.rb', line 8 def row_data @row_data end |
Instance Method Details
#execute ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/s3_file_handler/csv/append_row.rb', line 18 def execute read_result = S3FileHandler.read_file(bucket_name, file_key) return read_result unless read_result.success? new_csv_content = ::CSV.generate do |csv| csv << ::CSV.parse(read_result.data[:content]).flatten if read_result.data[:content] csv << row_data end S3FileHandler.upload_file(bucket_name, file_key, content: new_csv_content) end |