Class: S3::Object
Instance Attribute Summary collapse
-
#acl ⇒ Object
Returns the value of attribute acl.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
- #content(reload = false) ⇒ Object
-
#content_disposition ⇒ Object
Returns the value of attribute content_disposition.
-
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#etag ⇒ Object
readonly
Returns the value of attribute etag.
-
#key ⇒ Object
Returns the value of attribute key.
-
#last_modified ⇒ Object
readonly
Returns the value of attribute last_modified.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #cname_url ⇒ Object
- #copy(options = {}) ⇒ Object
- #destroy ⇒ Object
- #exists? ⇒ Boolean
- #full_key ⇒ Object
-
#initialize(bucket, key, options = {}) ⇒ Object
constructor
A new instance of Object.
- #inspect ⇒ Object
- #retrieve ⇒ Object
- #save ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(bucket, key, options = {}) ⇒ Object
Returns a new instance of Object.
91 92 93 94 95 96 97 |
# File 'lib/s3/object.rb', line 91 def initialize(bucket, key, = {}) self.bucket = bucket self.key = key self.last_modified = [:last_modified] self.etag = [:etag] self.size = [:size] end |
Instance Attribute Details
#acl ⇒ Object
Returns the value of attribute acl.
6 7 8 |
# File 'lib/s3/object.rb', line 6 def acl @acl end |
#bucket ⇒ Object
Returns the value of attribute bucket.
6 7 8 |
# File 'lib/s3/object.rb', line 6 def bucket @bucket end |
#content(reload = false) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/s3/object.rb', line 38 def content(reload = false) if reload or @content.nil? response = object_request(:get) parse_headers(response) self.content = response.body end @content end |
#content_disposition ⇒ Object
Returns the value of attribute content_disposition.
5 6 7 |
# File 'lib/s3/object.rb', line 5 def content_disposition @content_disposition end |
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
5 6 7 |
# File 'lib/s3/object.rb', line 5 def content_encoding @content_encoding end |
#content_type ⇒ Object
Returns the value of attribute content_type.
5 6 7 |
# File 'lib/s3/object.rb', line 5 def content_type @content_type end |
#etag ⇒ Object
Returns the value of attribute etag.
6 7 8 |
# File 'lib/s3/object.rb', line 6 def etag @etag end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/s3/object.rb', line 6 def key @key end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
6 7 8 |
# File 'lib/s3/object.rb', line 6 def last_modified @last_modified end |
#size ⇒ Object
Returns the value of attribute size.
6 7 8 |
# File 'lib/s3/object.rb', line 6 def size @size end |
Instance Method Details
#cname_url ⇒ Object
83 84 85 |
# File 'lib/s3/object.rb', line 83 def cname_url "#{protocol}#{name}/#{key}" if bucket.vhost? end |
#copy(options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/s3/object.rb', line 54 def copy( = {}) key = [:key] || self.key bucket = [:bucket] || self.bucket headers = {} headers[:x_amz_acl] = [:acl] || acl || "public-read" headers[:content_type] = [:content_type] || content_type || "application/octet-stream" headers[:content_encoding] = [:content_encoding] if [:content_encoding] headers[:content_disposition] = [:content_disposition] if [:content_disposition] headers[:x_amz_copy_source] = full_key headers[:x_amz_metadata_directive] = "REPLACE" headers[:x_amz_copy_source_if_match] = [:if_match] if [:if_match] headers[:x_amz_copy_source_if_none_match] = [:if_none_match] if [:if_none_match] headers[:x_amz_copy_source_if_unmodified_since] = [:if_modified_since] if [:if_modified_since] headers[:x_amz_copy_source_if_modified_since] = [:if_unmodified_since] if [:if_unmodified_since] response = bucket.send(:bucket_request, :put, :path => key, :headers => headers) self.class.parse_copied(:object => self, :bucket => bucket, :key => key, :body => response.body, :headers => headers) end |
#destroy ⇒ Object
74 75 76 77 |
# File 'lib/s3/object.rb', line 74 def destroy object_request(:delete) true end |
#exists? ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/s3/object.rb', line 31 def exists? retrieve true rescue Error::NoSuchKey false end |
#full_key ⇒ Object
12 13 14 |
# File 'lib/s3/object.rb', line 12 def full_key [name, key].join("/") end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/s3/object.rb', line 87 def inspect "#<#{self.class}:/#{name}/#{key}>" end |
#retrieve ⇒ Object
25 26 27 28 29 |
# File 'lib/s3/object.rb', line 25 def retrieve response = object_request(:get, :headers => { :range => 0..0 }) parse_headers(response) self end |
#save ⇒ Object
47 48 49 50 51 52 |
# File 'lib/s3/object.rb', line 47 def save body = content.is_a?(IO) ? content.read : content response = object_request(:put, :body => body, :headers => dump_headers) parse_headers(response) true end |
#url ⇒ Object
79 80 81 |
# File 'lib/s3/object.rb', line 79 def url "#{protocol}#{host}/#{path_prefix}#{key}" end |