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



9
10
11
12
# File 'lib/fog/aws/models/s3/objects.rb', line 9

def all(options = {})
  merge_attributes(:options => options)
  bucket.buckets.get(bucket.name, @options).objects
end

#bucketObject



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

def bucket
  @bucket
end

#create(attributes = {}) ⇒ Object



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

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

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/aws/models/s3/objects.rb', line 24

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

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fog/aws/models/s3/objects.rb', line 45

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



65
66
67
68
69
70
71
# File 'lib/fog/aws/models/s3/objects.rb', line 65

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

#reloadObject



73
74
75
# File 'lib/fog/aws/models/s3/objects.rb', line 73

def reload
  all(@options)
end