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