Class: Fog::Storage::OpenStack::File

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

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

Methods included from Attributes::ClassMethods

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

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#bodyObject



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

def body
  attributes[:body] ||= if last_modified
    collection.get(identity).body
  else
    ''
  end
end

#body=(new_body) ⇒ Object



26
27
28
# File 'lib/fog/openstack/models/storage/file.rb', line 26

def body=(new_body)
  attributes[:body] = new_body
end

#copy(target_directory_key, target_file_key, options = {}) ⇒ Object



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

def copy(target_directory_key, target_file_key, options={})
  requires :directory, :key
  options['Content-Type'] ||= content_type if content_type
  options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin
  options['Origin'] ||= origin if origin
  service.copy_object(directory.key, key, target_directory_key, target_file_key, options)
  target_directory = service.directories.new(:key => target_directory_key)
  target_directory.files.get(target_file_key)
end

#destroyObject



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

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

#directoryObject



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

def directory
  @directory
end

#metadataObject



50
51
52
# File 'lib/fog/openstack/models/storage/file.rb', line 50

def 
  @metadata ||= 
end

#owner=(new_owner) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/fog/openstack/models/storage/file.rb', line 54

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

#public=(new_public) ⇒ Object



63
64
65
# File 'lib/fog/openstack/models/storage/file.rb', line 63

def public=(new_public)
  new_public
end

#public_urlObject



67
68
69
70
# File 'lib/fog/openstack/models/storage/file.rb', line 67

def public_url
  requires :key
  self.collection.get_url(self.key)
end

#save(options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fog/openstack/models/storage/file.rb', line 72

def save(options = {})
  requires :body, :directory, :key
  options['Content-Type'] = content_type if content_type
  options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin
  options['Origin'] = origin if origin
  options.merge!()

  data = service.put_object(directory.key, key, body, options)
  update_attributes_from(data)
  

  self.content_length = Fog::Storage.get_body_size(body)
  self.content_type ||= Fog::Storage.get_content_type(body)
  true
end