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, #inspect, #merge_attributes

Constructor Details

#initialize(attributes = {}) ⇒ Objects

Returns a new instance of Objects.



12
13
14
# File 'lib/fog/aws/models/s3/objects.rb', line 12

def initialize(attributes = {})
  super
end

Instance Method Details

#all(options = {}) ⇒ Object



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

def all(options = {})
  merge_attributes(options)
  self.delete_if {true}
  objects = bucket.buckets.get(bucket.name, attributes).objects
  objects.keys.each do |key|
    self[key] = objects[key]
  end
  self
end

#bucketObject



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

def bucket
  @bucket
end

#create(attributes = {}) ⇒ Object



30
31
32
33
34
# File 'lib/fog/aws/models/s3/objects.rb', line 30

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

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/aws/models/s3/objects.rb', line 36

def get(key, options = {})
  data = connection.get_object(bucket.name, key, options)
  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
  self[object_data['key']] = Fog::AWS::S3::Object.new({
    :bucket     => bucket,
    :connection => connection,
    :objects    => self
  }.merge!(object_data))
rescue Fog::Errors::NotFound
  nil
end

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



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 56

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', 'ETag', 'Last-Modified'].include?(key)
      object_data[key] = value
    end
  end
  self[object_data['key']] = Fog::AWS::S3::Object.new({
    :bucket     => bucket,
    :connection => connection,
    :objects    => self
  }.merge!(object_data))
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
# File 'lib/fog/aws/models/s3/objects.rb', line 83

def reload
  all
end