Class: UberS3::Object
- Inherits:
-
Object
- Object
- UberS3::Object
- Includes:
- UberS3::Operation::Object::AccessPolicy, UberS3::Operation::Object::ContentDisposition, UberS3::Operation::Object::ContentEncoding, UberS3::Operation::Object::ContentMd5, UberS3::Operation::Object::ContentType, UberS3::Operation::Object::HttpCache, UberS3::Operation::Object::Meta, UberS3::Operation::Object::StorageClass
- Defined in:
- lib/uber-s3/object.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#error ⇒ Object
Returns the value of attribute error.
-
#key ⇒ Object
Returns the value of attribute key.
-
#size ⇒ Object
Returns the value of attribute size.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #fetch ⇒ Object
-
#initialize(bucket, key, value = nil, options = {}) ⇒ Object
constructor
A new instance of Object.
- #persisted? ⇒ Boolean
- #save ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
Methods included from UberS3::Operation::Object::StorageClass
Methods included from UberS3::Operation::Object::Meta
Methods included from UberS3::Operation::Object::HttpCache
Methods included from UberS3::Operation::Object::ContentType
Methods included from UberS3::Operation::Object::ContentMd5
Methods included from UberS3::Operation::Object::ContentEncoding
Methods included from UberS3::Operation::Object::ContentDisposition
Methods included from UberS3::Operation::Object::AccessPolicy
Constructor Details
#initialize(bucket, key, value = nil, options = {}) ⇒ Object
Returns a new instance of Object.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/uber-s3/object.rb', line 14 def initialize(bucket, key, value=nil, ={}) self.bucket = bucket self.key = key self.value = value # Init current state infer_content_type! # Call operation methods based on options passed bucket.connection.defaults.merge().each {|k,v| self.send((k.to_s+'=').to_sym, v) } end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
12 13 14 |
# File 'lib/uber-s3/object.rb', line 12 def bucket @bucket end |
#error ⇒ Object
Returns the value of attribute error.
12 13 14 |
# File 'lib/uber-s3/object.rb', line 12 def error @error end |
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/uber-s3/object.rb', line 12 def key @key end |
#size ⇒ Object
Returns the value of attribute size.
12 13 14 |
# File 'lib/uber-s3/object.rb', line 12 def size @size end |
#value ⇒ Object
Returns the value of attribute value.
12 13 14 |
# File 'lib/uber-s3/object.rb', line 12 def value @value end |
Instance Method Details
#delete ⇒ Object
85 86 87 |
# File 'lib/uber-s3/object.rb', line 85 def delete bucket.connection.delete(key).status == 204 end |
#exists? ⇒ Boolean
30 31 32 |
# File 'lib/uber-s3/object.rb', line 30 def exists? bucket.connection.head(key).status == 200 end |
#fetch ⇒ Object
34 35 36 37 |
# File 'lib/uber-s3/object.rb', line 34 def fetch self.value = bucket.connection.get(key).body self end |
#persisted? ⇒ Boolean
94 95 96 |
# File 'lib/uber-s3/object.rb', line 94 def persisted? # TODO end |
#save ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/uber-s3/object.rb', line 39 def save headers = {} # Encode data if necessary gzip_content! # Standard pass through values headers['Content-Disposition'] = content_disposition headers['Content-Encoding'] = content_encoding headers['Content-Length'] = size.to_s headers['Content-Type'] = content_type headers['Cache-Control'] = cache_control headers['Expires'] = expires headers['Pragma'] = pragma headers.each {|k,v| headers.delete(k) if v.nil? || v.empty? } # Content MD5 integrity check if !content_md5.nil? self.content_md5 = Digest::MD5.hexdigest(value) if content_md5 == true # We expect a md5 hex digest here md5_digest = content_md5.unpack('a2'*16).collect {|i| i.hex.chr }.join headers['Content-MD5'] = Base64.encode64(md5_digest).strip end # ACL if !access.nil? headers['x-amz-acl'] = access.to_s.gsub('_', '-') end # Storage class if !storage_class.nil? headers['x-amz-storage-class'] = storage_class.to_s.upcase end # Let's do it response = bucket.connection.put(key, headers, value) # Update error state self.error = response.error # Test for success.... response.status == 200 end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/uber-s3/object.rb', line 26 def to_s "#<#{self.class} @key=\"#{self.key}\">" end |
#url ⇒ Object
98 99 100 |
# File 'lib/uber-s3/object.rb', line 98 def url # TODO end |