Class: OpenStax::Aws::S3TextFile
- Inherits:
-
Object
- Object
- OpenStax::Aws::S3TextFile
- Defined in:
- lib/openstax/aws/s3_text_file.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#bucket_region ⇒ Object
readonly
Returns the value of attribute bucket_region.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #delete ⇒ Object
- #get ⇒ Object
-
#initialize(bucket_name:, bucket_region:, key:) ⇒ S3TextFile
constructor
A new instance of S3TextFile.
- #object ⇒ Object
- #read ⇒ Object
- #write(string_contents:, content_type: 'text/plain', cache_control: nil) ⇒ Object
Constructor Details
#initialize(bucket_name:, bucket_region:, key:) ⇒ S3TextFile
Returns a new instance of S3TextFile.
6 7 8 9 10 11 12 13 14 |
# 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 |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
4 5 6 |
# File 'lib/openstax/aws/s3_text_file.rb', line 4 def bucket_name @bucket_name end |
#bucket_region ⇒ Object (readonly)
Returns the value of attribute bucket_region.
4 5 6 |
# File 'lib/openstax/aws/s3_text_file.rb', line 4 def bucket_region @bucket_region end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/openstax/aws/s3_text_file.rb', line 4 def key @key end |
Instance Method Details
#delete ⇒ Object
37 38 39 |
# File 'lib/openstax/aws/s3_text_file.rb', line 37 def delete object.delete end |
#get ⇒ Object
21 22 23 24 |
# File 'lib/openstax/aws/s3_text_file.rb', line 21 def get object.load object.get end |
#object ⇒ Object
41 42 43 44 45 46 47 |
# 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 ⇒ Object
16 17 18 19 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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 |