Class: Fog::Storage::OpenStack::File
- Inherits:
-
OpenStack::Model
- Object
- Model
- OpenStack::Model
- Fog::Storage::OpenStack::File
- Defined in:
- lib/fog/storage/openstack/models/file.rb
Instance Attribute Summary collapse
-
#content_encoding ⇒ Object
When you create an object or update its metadata, you can optionally set the Content-Encoding metadata.
-
#delete_after ⇒ Integer
A number of seconds representing how long from now this object will be automatically deleted.
-
#delete_at ⇒ Integer
A Unix Epoch Timestamp, in integer form, representing the time when this object will be automatically deleted.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Attributes inherited from OpenStack::Model
Instance Method Summary collapse
- #body ⇒ Object
- #body=(new_body) ⇒ Object
- #copy(target_directory_key, target_file_key, options = {}) ⇒ Object
- #destroy ⇒ Object
-
#initialize(new_attributes = {}) ⇒ File
constructor
A new instance of File.
- #metadata ⇒ Object
- #owner=(new_owner) ⇒ Object
- #public=(new_public) ⇒ Object
- #public_url ⇒ Object
- #save(options = {}) ⇒ Object
-
#url(expires, options = {}) ⇒ String
Get a url for file.
Methods inherited from OpenStack::Model
Constructor Details
#initialize(new_attributes = {}) ⇒ File
Returns a new instance of File.
36 37 38 39 |
# File 'lib/fog/storage/openstack/models/file.rb', line 36 def initialize(new_attributes = {}) super @dirty = if last_modified then false else true end end |
Instance Attribute Details
#content_encoding ⇒ Object
When you create an object or update its metadata, you can optionally set the Content-Encoding metadata. This metadata enables you to indicate that the object content is compressed without losing the identity of the underlying media type (Content-Type) of the file, such as a video.
34 |
# File 'lib/fog/storage/openstack/models/file.rb', line 34 attribute :content_encoding, :aliases => 'Content-Encoding' |
#delete_after ⇒ Integer
A number of seconds representing how long from now this object will be automatically deleted.
27 |
# File 'lib/fog/storage/openstack/models/file.rb', line 27 attribute :delete_after, :aliases => ['X-Delete-After'] |
#delete_at ⇒ Integer
A Unix Epoch Timestamp, in integer form, representing the time when this object will be automatically deleted.
21 |
# File 'lib/fog/storage/openstack/models/file.rb', line 21 attribute :delete_at, :aliases => ['X-Delete-At'] |
#directory ⇒ Object
Returns the value of attribute directory.
54 55 56 |
# File 'lib/fog/storage/openstack/models/file.rb', line 54 def directory @directory end |
Instance Method Details
#body ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/fog/storage/openstack/models/file.rb', line 41 def body attributes[:body] ||= if last_modified collection.get(identity).body else '' end end |
#body=(new_body) ⇒ Object
49 50 51 52 |
# File 'lib/fog/storage/openstack/models/file.rb', line 49 def body=(new_body) attributes[:body] = new_body @dirty = true end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fog/storage/openstack/models/file.rb', line 56 def copy(target_directory_key, target_file_key, = {}) requires :directory, :key ['Content-Type'] ||= content_type if content_type ['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin ['Origin'] ||= origin if origin ['Content-Encoding'] ||= content_encoding if content_encoding service.copy_object(directory.key, key, target_directory_key, target_file_key, ) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.get(target_file_key) end |
#destroy ⇒ Object
67 68 69 70 71 72 |
# File 'lib/fog/storage/openstack/models/file.rb', line 67 def destroy requires :directory, :key service.delete_object(directory.key, key) @dirty = true true end |
#metadata ⇒ Object
74 75 76 |
# File 'lib/fog/storage/openstack/models/file.rb', line 74 def attributes[:metadata] ||= end |
#owner=(new_owner) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/fog/storage/openstack/models/file.rb', line 78 def owner=(new_owner) if new_owner attributes[:owner] = { :display_name => new_owner['DisplayName'], :id => new_owner['ID'] } end end |
#public=(new_public) ⇒ Object
87 88 89 |
# File 'lib/fog/storage/openstack/models/file.rb', line 87 def public=(new_public) new_public end |
#public_url ⇒ Object
104 105 106 107 |
# File 'lib/fog/storage/openstack/models/file.rb', line 104 def public_url requires :key collection.get_url(key) end |
#save(options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/fog/storage/openstack/models/file.rb', line 109 def save( = {}) requires :directory, :key ['Content-Type'] = content_type if content_type ['Content-Disposition'] = content_disposition if content_disposition ['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin ['Origin'] = origin if origin ['X-Delete-At'] = delete_at if delete_at ['X-Delete-After'] = delete_after if delete_after ['Content-Encoding'] = content_encoding if content_encoding .merge!() if not @dirty data = service.post_object(directory.key, key, ) else requires :body data = service.put_object(directory.key, key, body, ) self.content_length = Fog::Storage.get_body_size(body) self.content_type ||= Fog::Storage.get_content_type(body) end update_attributes_from(data) true end |
#url(expires, options = {}) ⇒ String
Get a url for file.
required attributes: key
99 100 101 102 |
# File 'lib/fog/storage/openstack/models/file.rb', line 99 def url(expires, = {}) requires :directory, :key service.create_temp_url(directory.key, key, expires, "GET", ) end |