Class: Stree::Object
- Inherits:
-
Object
- Object
- Stree::Object
- Extended by:
- Forwardable
- Includes:
- Parser
- Defined in:
- lib/stree/object.rb
Overview
Class responsible for handling objects stored in S3 buckets
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
Download the content of the object, and caches it.
-
#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
-
#==(other) ⇒ Object
Compares the object with other object.
-
#cname_url ⇒ Object
Returns Object’s CNAME URL (without s3.amazonaws.com suffix) using protocol specified in Service, e.g.
-
#copy(options = {}) ⇒ Object
Copies the file to another key and/or bucket.
-
#destroy ⇒ Object
Destroys the file on the server.
-
#exists? ⇒ Boolean
Retrieves the object from the server, returns true if the object exists or false otherwise.
-
#full_key ⇒ Object
Returns full key of the object: e.g.
-
#inspect ⇒ Object
:nodoc:.
-
#retrieve ⇒ Object
Retrieves the object from the server.
-
#save ⇒ Object
Saves the object, returns true if successfull.
-
#url ⇒ Object
Returns Object’s URL using protocol specified in Service, e.g.
Methods included from Parser
#parse_copy_object_result, #parse_error, #parse_list_all_my_buckets_result, #parse_list_bucket_result, #parse_location_constraint, #rexml_document
Instance Attribute Details
#acl ⇒ Object
Returns the value of attribute acl.
9 10 11 |
# File 'lib/stree/object.rb', line 9 def acl @acl end |
#bucket ⇒ Object
Returns the value of attribute bucket.
9 10 11 |
# File 'lib/stree/object.rb', line 9 def bucket @bucket end |
#content(reload = false) ⇒ Object
Download the content of the object, and caches it. Pass true to clear the cache and download the object again.
64 65 66 67 68 69 |
# File 'lib/stree/object.rb', line 64 def content(reload = false) if reload or @content.nil? get_object end @content end |
#content_disposition ⇒ Object
Returns the value of attribute content_disposition.
8 9 10 |
# File 'lib/stree/object.rb', line 8 def content_disposition @content_disposition end |
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
8 9 10 |
# File 'lib/stree/object.rb', line 8 def content_encoding @content_encoding end |
#content_type ⇒ Object
Returns the value of attribute content_type.
8 9 10 |
# File 'lib/stree/object.rb', line 8 def content_type @content_type end |
#etag ⇒ Object
Returns the value of attribute etag.
9 10 11 |
# File 'lib/stree/object.rb', line 9 def etag @etag end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/stree/object.rb', line 9 def key @key end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
9 10 11 |
# File 'lib/stree/object.rb', line 9 def last_modified @last_modified end |
#size ⇒ Object
Returns the value of attribute size.
9 10 11 |
# File 'lib/stree/object.rb', line 9 def size @size end |
Instance Method Details
#==(other) ⇒ Object
Compares the object with other object. Returns true if the key of the objects are the same, and both have the same buckets (see bucket equality)
19 20 21 |
# File 'lib/stree/object.rb', line 19 def ==(other) self.key == other.key and self.bucket == other.bucket end |
#cname_url ⇒ Object
Returns Object’s CNAME URL (without s3.amazonaws.com suffix) using protocol specified in Service, e.g. domain.com/key/with/path.extension. (you have to set the CNAME in your DNS before you use the CNAME URL schema).
103 104 105 |
# File 'lib/stree/object.rb', line 103 def cname_url URI.escape("#{protocol}#{name}/#{key}") if bucket.vhost? end |
#copy(options = {}) ⇒ Object
Copies the file to another key and/or bucket.
Options:
key
-
new key to store object in
bucket
-
new bucket to store object in (instance of Stree::Bucket)
acl
-
acl of the copied object (default: “public-read”)
content_type
-
content type of the copied object (default: “application/octet-stream”)
83 84 85 |
# File 'lib/stree/object.rb', line 83 def copy( = {}) copy_object() end |
#destroy ⇒ Object
Destroys the file on the server
88 89 90 91 |
# File 'lib/stree/object.rb', line 88 def destroy delete_object true end |
#exists? ⇒ Boolean
Retrieves the object from the server, returns true if the object exists or false otherwise. Uses retrieve method, but catches NoSuchKey exception and returns false when it happens
55 56 57 58 59 60 |
# File 'lib/stree/object.rb', line 55 def exists? retrieve true rescue Error::NoSuchKey false end |
#full_key ⇒ Object
Returns full key of the object: e.g. bucket-name/object/key.ext
24 25 26 |
# File 'lib/stree/object.rb', line 24 def full_key [name, key].join("/") end |
#inspect ⇒ Object
:nodoc:
107 108 109 |
# File 'lib/stree/object.rb', line 107 def inspect #:nodoc: "#<#{self.class}:/#{name}/#{key}>" end |
#retrieve ⇒ Object
Retrieves the object from the server. Method is used to download object information only (content-type, size and so on). It does NOT download the content of the object (use the content method to do it).
47 48 49 50 |
# File 'lib/stree/object.rb', line 47 def retrieve get_object(:headers => { :range => 0..0 }) self end |
#save ⇒ Object
Saves the object, returns true if successfull.
72 73 74 75 |
# File 'lib/stree/object.rb', line 72 def save put_object true end |
#url ⇒ Object
Returns Object’s URL using protocol specified in Service, e.g. domain.com.s3.amazonaws.com/key/with/path.extension
95 96 97 |
# File 'lib/stree/object.rb', line 95 def url URI.escape("#{protocol}#{host}/#{path_prefix}#{key}") end |