Class: Fog::AWS::S3::Objects

Inherits:
Collection show all
Defined in:
lib/fog/aws/models/s3/objects.rb

Instance Method Summary collapse

Methods inherited from Collection

aliases, attribute, attributes, #attributes, #initialize, #inspect, #merge_attributes

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#all(options = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/fog/aws/models/s3/objects.rb', line 13

def all(options = {})
  bucket.buckets.get(
    bucket.name,
    options.reject {|key, value| !['delimiter', 'marker', 'max-keys', 'prefix'].include?(key)}
  ).objects
end

#bucketObject



20
21
22
# File 'lib/fog/aws/models/s3/objects.rb', line 20

def bucket
  @bucket
end

#create(attributes = {}) ⇒ Object



24
25
26
27
28
# File 'lib/fog/aws/models/s3/objects.rb', line 24

def create(attributes = {})
  object = new(attributes)
  object.save
  object
end

#get(key, options = {}, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/aws/models/s3/objects.rb', line 30

def get(key, options = {}, &block)
  data = connection.get_object(bucket.name, key, options, &block)
  object_data = {
    :body => data.body,
    :key  => key
  }
  for key, value in data.headers
    if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
      object_data[key] = value
    end
  end
  object = Fog::AWS::S3::Object.new({
    :bucket     => bucket,
    :connection => connection,
    :objects    => self
  }.merge!(object_data))
  object
rescue Fog::Errors::NotFound
  nil
end

#get_url(key, expires) ⇒ Object



51
52
53
# File 'lib/fog/aws/models/s3/objects.rb', line 51

def get_url(key, expires)
  connection.get_object_url(bucket.name, key, expires)
end

#head(key, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fog/aws/models/s3/objects.rb', line 55

def head(key, options = {})
  data = connection.head_object(bucket.name, key, options)
  object_data = {
    :key => key
  }
  for key, value in data.headers
    if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
      object_data[key] = value
    end
  end
  object = Fog::AWS::S3::Object.new({
    :bucket     => bucket,
    :connection => connection,
    :objects    => self
  }.merge!(object_data))
  object
rescue Fog::Errors::NotFound
  nil
end

#new(attributes = {}) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/fog/aws/models/s3/objects.rb', line 75

def new(attributes = {})
  Fog::AWS::S3::Object.new({
    :bucket     => bucket,
    :connection => connection,
    :objects    => self
  }.merge!(attributes))
end

#reloadObject



83
84
85
86
87
88
89
90
# File 'lib/fog/aws/models/s3/objects.rb', line 83

def reload
  all({
    'delimiter'   => @delimiter,
    'marker'      => @marker,
    'max-keys'    => @max_keys,
    'prefix'      => @prefix
  })
end