Class: S3FileHandler::File::Exists

Inherits:
BaseOperation show all
Defined in:
lib/s3_file_handler/file/exists.rb

Instance Attribute Summary collapse

Attributes inherited from BaseOperation

#client, #errors

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Exists.



8
9
10
11
12
13
# File 'lib/s3_file_handler/file/exists.rb', line 8

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

  @bucket_name = bucket_name
  @file_key = file_key
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



6
7
8
# File 'lib/s3_file_handler/file/exists.rb', line 6

def bucket_name
  @bucket_name
end

#file_keyObject (readonly)

Returns the value of attribute file_key.



6
7
8
# File 'lib/s3_file_handler/file/exists.rb', line 6

def file_key
  @file_key
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
# File 'lib/s3_file_handler/file/exists.rb', line 15

def execute
  client.head_object(bucket: bucket_name, key: file_key)
  result({ exists: true })
rescue Aws::S3::Errors::NotFound
  result({ exists: false })
rescue Aws::S3::Errors::ServiceError => e
  errors << "AWS S3 API error: #{e.message}"
  result
end