Class: S3FileHandler::Folder::Exists

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

Instance Attribute Summary collapse

Attributes inherited from BaseOperation

#client, #errors

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Exists.



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

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

  @bucket_name = bucket_name
  @folder_name = folder_name.end_with?('/') ? folder_name : "#{folder_name}/"
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



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

def bucket_name
  @bucket_name
end

#folder_nameObject (readonly)

Returns the value of attribute folder_name.



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

def folder_name
  @folder_name
end

Instance Method Details

#executeObject



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

def execute
  handle_aws_errors do
    response = client.list_objects_v2(
      bucket: bucket_name,
      prefix: folder_name,
      max_keys: 1
    )
    
    result({ exists: response.key_count > 0 })
  end
end