Class: FakeAWS::S3::S3Object
- Inherits:
-
Object
- Object
- FakeAWS::S3::S3Object
- Defined in:
- lib/fake_aws/s3/s3_object.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #content_length ⇒ Object
- #copy_from(source, options = {}) ⇒ Object
- #copy_to(target, options = {}) ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(bucket, key) ⇒ S3Object
constructor
A new instance of S3Object.
- #read ⇒ Object
- #write(data, options = {}) ⇒ Object
Constructor Details
#initialize(bucket, key) ⇒ S3Object
Returns a new instance of S3Object.
6 7 8 9 10 |
# File 'lib/fake_aws/s3/s3_object.rb', line 6 def initialize(bucket, key) @bucket = bucket @key = key @metadata = {} end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
12 13 14 |
# File 'lib/fake_aws/s3/s3_object.rb', line 12 def bucket @bucket end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
13 14 15 |
# File 'lib/fake_aws/s3/s3_object.rb', line 13 def key @key end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
14 15 16 |
# File 'lib/fake_aws/s3/s3_object.rb', line 14 def @metadata end |
Instance Method Details
#content_length ⇒ Object
40 41 42 43 |
# File 'lib/fake_aws/s3/s3_object.rb', line 40 def content_length must_exist! @data.length end |
#copy_from(source, options = {}) ⇒ Object
36 37 38 |
# File 'lib/fake_aws/s3/s3_object.rb', line 36 def copy_from(source, = {}) write(resolve_object_reference(source, ).read) end |
#copy_to(target, options = {}) ⇒ Object
32 33 34 |
# File 'lib/fake_aws/s3/s3_object.rb', line 32 def copy_to(target, = {}) resolve_object_reference(target, ).write(self.read) end |
#delete ⇒ Object
49 50 51 |
# File 'lib/fake_aws/s3/s3_object.rb', line 49 def delete @data = nil end |
#exists? ⇒ Boolean
45 46 47 |
# File 'lib/fake_aws/s3/s3_object.rb', line 45 def exists? !!@data end |
#read ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/fake_aws/s3/s3_object.rb', line 22 def read must_exist! if block_given? @data.each_line do |line| yield line end end @data end |
#write(data, options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/fake_aws/s3/s3_object.rb', line 16 def write(data, = {}) data = data.read if data.respond_to?(:read) data = data.dup.force_encoding("BINARY") if data.respond_to?(:force_encoding) @data = data end |