Class: Fog::AWS::S3::Object

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/s3/object.rb

Instance Method Summary collapse

Methods inherited from Model

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

Constructor Details

#initialize(attributes = {}) ⇒ Object

Returns a new instance of Object.



17
18
19
# File 'lib/fog/aws/models/s3/object.rb', line 17

def initialize(attributes = {})
  super
end

Instance Method Details

#bucketObject



21
22
23
# File 'lib/fog/aws/models/s3/object.rb', line 21

def bucket
  @bucket
end

#copy(target_bucket_name, target_object_key) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/aws/models/s3/object.rb', line 25

def copy(target_bucket_name, target_object_key)
  data = connection.copy_object(bucket.name, @key, target_bucket_name, target_object_key).body
  target_bucket = connection.buckets.new(:name => target_bucket_name)
  target_object = target_bucket.objects.new(attributes.merge!(:key => target_object_key))
  copy_data = {}
  for key, value in data
    if ['ETag', 'LastModified'].include?(key)
      copy_data[key] = value
    end
  end
  target_object.merge_attributes(copy_data)
  target_object.objects[target_object_key] = target_object
  target_object
end

#destroyObject



40
41
42
43
44
# File 'lib/fog/aws/models/s3/object.rb', line 40

def destroy
  connection.delete_object(bucket.name, @key)
  objects.delete(@key)
  true
end

#objectsObject



46
47
48
# File 'lib/fog/aws/models/s3/object.rb', line 46

def objects
  @objects
end

#reloadObject



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

def reload
  new_attributes = objects.get(@key).attributes
  merge_attributes(new_attributes)
end

#save(options = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/fog/aws/models/s3/object.rb', line 55

def save(options = {})
  data = connection.put_object(bucket.name, @key, @body, options)
  @etag = data.headers['ETag']
  objects[@key] = self
  true
end