Class: Brutalismbot::S3::Client
- Inherits:
-
Object
- Object
- Brutalismbot::S3::Client
- Defined in:
- lib/brutalismbot/s3/client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #get(key, &block) ⇒ Object
-
#initialize(bucket: nil, prefix: nil, client: nil) ⇒ Client
constructor
A new instance of Client.
- #list(**options, &block) ⇒ Object
Constructor Details
#initialize(bucket: nil, prefix: nil, client: nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 |
# File 'lib/brutalismbot/s3/client.rb', line 8 def initialize(bucket:nil, prefix:nil, client:nil) bucket ||= ENV["S3_BUCKET"] || "brutalismbot" prefix ||= ENV["S3_PREFIX"] || "data/v1/" client ||= Aws::S3::Client.new @bucket = Aws::S3::Bucket.new(name: bucket, client: client) @client = client @prefix = prefix end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
6 7 8 |
# File 'lib/brutalismbot/s3/client.rb', line 6 def bucket @bucket end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/brutalismbot/s3/client.rb', line 6 def client @client end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/brutalismbot/s3/client.rb', line 6 def prefix @prefix end |
Instance Method Details
#get(key, &block) ⇒ Object
17 18 19 20 21 |
# File 'lib/brutalismbot/s3/client.rb', line 17 def get(key, &block) Brutalismbot.logger.info("GET s3://#{@bucket.name}/#{key}") object = @bucket.object(key) block_given? ? yield(object) : object end |
#list(**options, &block) ⇒ Object
23 24 25 26 27 |
# File 'lib/brutalismbot/s3/client.rb', line 23 def list(**, &block) [:prefix] ||= @prefix Brutalismbot.logger.info("LIST s3://#{@bucket.name}/#{[:prefix]}*") Prefix.new(@bucket.objects(), &block) end |