Class: S3::Bucket

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Roxy::Moxie
Defined in:
lib/s3/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Roxy::Moxie

proxy

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

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/s3/bucket.rb', line 6

def name
  @name
end

#serviceObject

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

#destroyObject



35
36
37
38
# File 'lib/s3/bucket.rb', line 35

def destroy
  bucket_request(:delete)
  true
end

#exists?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/s3/bucket.rb', line 28

def exists?
  retrieve
  true
rescue Error::NoSuchBucket
  false
end

#hostObject



55
56
57
# File 'lib/s3/bucket.rb', line 55

def host
  vhost? ? "#@name.#{HOST}" : "#{HOST}"
end

#inspectObject



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, options = {})
  if options.empty?
    if reload or @objects.nil?
      @objects = fetch_objects
    else
      @objects
    end
  else
    fetch_objects(options)
  end
end

#path_prefixObject



59
60
61
# File 'lib/s3/bucket.rb', line 59

def path_prefix
  vhost? ? "" : "#@name/"
end

#retrieveObject



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
  options = { :headers => {} }
  if location and location != "US"
    options[:body] = "<CreateBucketConfiguration><LocationConstraint>#{location}</LocationConstraint></CreateBucketConfiguration>"
    options[:headers][:content_type] = "application/xml"
  end
  bucket_request(:put, options)
  true
end

#vhost?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/s3/bucket.rb', line 51

def vhost?
  "#@name.#{HOST}" =~ /\A#{URI::REGEXP::PATTERN::HOSTNAME}\Z/
end