class OpenStax::Aws::S3TextFile

Attributes

bucket_name[R]
bucket_region[R]
key[R]

Public Class Methods

new(bucket_name:, bucket_region:, key:) click to toggle source
# File lib/openstax/aws/s3_text_file.rb, line 6
def initialize(bucket_name:, bucket_region:, key:)
  raise ArgumentError, "bucket_name cannot be nil" if bucket_name.nil?
  raise ArgumentError, "bucket_region cannot be nil" if bucket_region.nil?
  raise ArgumentError, "key cannot be nil" if key.nil?

  @bucket_name = bucket_name
  @bucket_region = bucket_region
  @key = key
end

Public Instance Methods

delete() click to toggle source
# File lib/openstax/aws/s3_text_file.rb, line 37
def delete
  object.delete
end
get() click to toggle source
# File lib/openstax/aws/s3_text_file.rb, line 21
def get
  object.load
  object.get
end
object() click to toggle source
# File lib/openstax/aws/s3_text_file.rb, line 41
def object
  @object ||= Aws::S3::Object.new(
    bucket_name,
    key,
    client: Aws::S3::Client.new(region: bucket_region)
  )
end
read() click to toggle source
# File lib/openstax/aws/s3_text_file.rb, line 16
def read
  object.load
  object.get.body.read
end
write(string_contents:, content_type:'text/plain', cache_control: nil) click to toggle source
# File lib/openstax/aws/s3_text_file.rb, line 26
def write(string_contents:, content_type:'text/plain', cache_control: nil)
  args = {
    body: StringIO.new(string_contents)
  }

  args[:content_type] = content_type if !content_type.nil?
  args[:cache_control] = cache_control if !cache_control.nil?

  object.put(**args)
end