Class: Lexicon::Common::Remote::S3Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lexicon/common/remote/s3_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw:) ⇒ S3Client

Returns a new instance of S3Client.

Parameters:

  • raw (Aws::S3::Client)


11
12
13
# File 'lib/lexicon/common/remote/s3_client.rb', line 11

def initialize(raw:)
  @raw = raw
end

Instance Attribute Details

#rawAws::S3::Client (readonly)

Returns:

  • (Aws::S3::Client)


8
9
10
# File 'lib/lexicon/common/remote/s3_client.rb', line 8

def raw
  @raw
end

Instance Method Details

#bucket_exist?(name) ⇒ Boolean

Parameters:

  • name (String)

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'lib/lexicon/common/remote/s3_client.rb', line 24

def bucket_exist?(name)
  if raw.head_bucket(bucket: name)
    true
  else
    false
  end
rescue StandardError
  false
end

#ensure_bucket_absent(name) ⇒ Object

Parameters:

  • name (String)


35
36
37
38
39
# File 'lib/lexicon/common/remote/s3_client.rb', line 35

def ensure_bucket_absent(name)
  if bucket_exist?(name)
    raw.delete_bucket(bucket: name)
  end
end

#ls(bucket) ⇒ Array<Object>

Returns:

  • (Array<Object>)


16
17
18
19
20
# File 'lib/lexicon/common/remote/s3_client.rb', line 16

def ls(bucket)
  raw.list_objects_v2(bucket: bucket)
    .to_h
    .fetch(:contents, [])
end