Class: S3::Bucket
- Inherits:
-
Object
- Object
- S3::Bucket
- Extended by:
- Forwardable, Roxy::Moxie
- Defined in:
- lib/s3/bucket.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #destroy ⇒ Object
- #exists? ⇒ Boolean
- #host ⇒ Object
-
#initialize(service, name) ⇒ Bucket
constructor
A new instance of Bucket.
- #inspect ⇒ Object
- #location(reload = false) ⇒ Object
- #objects(reload = false, options = {}) ⇒ Object
- #path_prefix ⇒ Object
- #retrieve ⇒ Object
- #save(location = nil) ⇒ Object
- #vhost? ⇒ Boolean
Methods included from Roxy::Moxie
Constructor Details
#initialize(service, name) ⇒ Bucket
Returns a new instance of Bucket.
105 106 107 108 |
# File 'lib/s3/bucket.rb', line 105 def initialize(service, name) self.service = service self.name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/s3/bucket.rb', line 6 def name @name end |
#service ⇒ Object
Returns the value of attribute service.
6 7 8 |
# File 'lib/s3/bucket.rb', line 6 def service @service end |
Instance Method Details
#==(other) ⇒ Object
24 25 26 |
# File 'lib/s3/bucket.rb', line 24 def ==(other) self.name == other.name and self.service == other.service end |
#destroy ⇒ Object
35 36 37 38 |
# File 'lib/s3/bucket.rb', line 35 def destroy bucket_request(:delete) true end |
#exists? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/s3/bucket.rb', line 28 def exists? retrieve true rescue Error::NoSuchBucket false end |
#host ⇒ Object
55 56 57 |
# File 'lib/s3/bucket.rb', line 55 def host vhost? ? "#@name.#{HOST}" : "#{HOST}" end |
#inspect ⇒ Object
101 102 103 |
# File 'lib/s3/bucket.rb', line 101 def inspect "#<#{self.class}:#{name}>" end |
#location(reload = false) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/s3/bucket.rb', line 15 def location(reload = false) if reload or @location.nil? response = bucket_request(:get, :params => { :location => nil }) @location = parse_location(response.body) else @location end end |
#objects(reload = false, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/s3/bucket.rb', line 63 def objects(reload = false, = {}) if .empty? if reload or @objects.nil? @objects = fetch_objects else @objects end else fetch_objects() end end |
#path_prefix ⇒ Object
59 60 61 |
# File 'lib/s3/bucket.rb', line 59 def path_prefix vhost? ? "" : "#@name/" end |
#retrieve ⇒ Object
10 11 12 13 |
# File 'lib/s3/bucket.rb', line 10 def retrieve bucket_request(:get, :params => { :max_keys => 0 }) self end |
#save(location = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/s3/bucket.rb', line 40 def save(location = nil) location = location.to_s.upcase if location = { :headers => {} } if location and location != "US" [:body] = "<CreateBucketConfiguration><LocationConstraint>#{location}</LocationConstraint></CreateBucketConfiguration>" [:headers][:content_type] = "application/xml" end bucket_request(:put, ) true end |
#vhost? ⇒ Boolean
51 52 53 |
# File 'lib/s3/bucket.rb', line 51 def vhost? "#@name.#{HOST}" =~ /\A#{URI::REGEXP::PATTERN::HOSTNAME}\Z/ end |