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.
-
#response ⇒ Object
Returns the value of attribute response.
-
#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
- #head ⇒ 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 |
#response ⇒ Object
Returns the value of attribute response.
12 13 14 |
# File 'lib/uber-s3/object.rb', line 12 def response @response 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
103 104 105 |
# File 'lib/uber-s3/object.rb', line 103 def delete bucket.connection.delete(key).status == 204 end |
#exists? ⇒ Boolean
30 31 32 33 34 35 |
# File 'lib/uber-s3/object.rb', line 30 def exists? # TODO.. refactor this as if we've already called head # on the object, there is no need to do it again.. # perhaps move some things into class methods? bucket.connection.head(key).status == 200 end |
#fetch ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/uber-s3/object.rb', line 44 def fetch self.response = bucket.connection.get(key) self.value = response.body parse_response_header! self end |
#head ⇒ Object
37 38 39 40 41 42 |
# File 'lib/uber-s3/object.rb', line 37 def head self.response = bucket.connection.head(key) parse_response_header! self end |
#persisted? ⇒ Boolean
112 113 114 |
# File 'lib/uber-s3/object.rb', line 112 def persisted? # TODO end |
#save ⇒ Object
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/uber-s3/object.rb', line 52 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 # Meta if !.nil? && !.empty? .each {|k,v| headers["x-amz-meta-#{k}"] = v.to_s } 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
116 117 118 |
# File 'lib/uber-s3/object.rb', line 116 def url # TODO end |