Class: Fog::Rackspace::Storage::File

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/rackspace/models/storage/file.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #reload, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

This class inherits a constructor from Fog::Model

Instance Attribute Details

#bodyObject



17
18
19
20
21
22
23
# File 'lib/fog/rackspace/models/storage/file.rb', line 17

def body
  @body ||= if last_modified
    collection.get(identity).body
  else
    ''
  end
end

Instance Method Details

#destroyObject



29
30
31
32
33
# File 'lib/fog/rackspace/models/storage/file.rb', line 29

def destroy
  requires :directory, :key
  connection.delete_object(directory.key, @key)
  true
end

#directoryObject



25
26
27
# File 'lib/fog/rackspace/models/storage/file.rb', line 25

def directory
  @directory
end

#owner=(new_owner) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/fog/rackspace/models/storage/file.rb', line 35

def owner=(new_owner)
  if new_owner
    @owner = {
      :display_name => new_owner['DisplayName'],
      :id           => new_owner['ID']
    }
  end
end

#public=(new_public) ⇒ Object



44
45
46
# File 'lib/fog/rackspace/models/storage/file.rb', line 44

def public=(new_public)
  new_public
end

#public_urlObject



48
49
50
51
52
53
# File 'lib/fog/rackspace/models/storage/file.rb', line 48

def public_url
  requires :directory, :key
  if @directory.public_url
    "#{@directory.public_url}/#{key}"
  end
end

#save(options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fog/rackspace/models/storage/file.rb', line 55

def save(options = {})
  requires :body, :directory, :key
  data = connection.put_object(directory.key, @key, @body, options)
  merge_attributes(data.headers)
  if body.is_a?(String)
    self.content_length = body.size
  else
    self.content_length = ::File.size(body.path)
  end
  true
end