Class: Fog::Brightbox::Storage::File
- Inherits:
-
Model
- Object
- Model
- Fog::Brightbox::Storage::File
- Defined in:
- lib/fog/brightbox/models/storage/file.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
- #body ⇒ Object
- #body=(new_body) ⇒ Object
- #copy(target_directory_key, target_file_key, options = {}) ⇒ Object
- #destroy ⇒ Object
- #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.
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
27 28 29 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 27 def directory @directory end |
Instance Method Details
#body ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 15 def body attributes[:body] ||= if last_modified collection.get(identity).body else "" end end |
#body=(new_body) ⇒ Object
23 24 25 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 23 def body=(new_body) attributes[:body] = new_body end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 29 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 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
39 40 41 42 43 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 39 def destroy requires :directory, :key service.delete_object(directory.key, key) true end |
#metadata ⇒ Object
45 46 47 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 45 def @metadata ||= end |
#owner=(new_owner) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 49 def owner=(new_owner) if new_owner attributes[:owner] = { display_name: new_owner["DisplayName"], id: new_owner["ID"] } end end |
#public=(new_public) ⇒ Object
58 59 60 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 58 def public=(new_public) new_public end |
#public_url ⇒ Object
75 76 77 78 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 75 def public_url requires :key collection.get_url(key) end |
#save(options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 80 def save( = {}) requires :body, :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 .merge!() data = service.put_object(directory.key, key, body, ) update_attributes_from(data) self.content_length = Fog::Storage.get_body_size(body) self.content_type ||= Fog::Storage.get_content_type(body) true end |
#url(expires, options = {}) ⇒ String
Get a url for file.
required attributes: key
70 71 72 73 |
# File 'lib/fog/brightbox/models/storage/file.rb', line 70 def url(expires, = {}) requires :directory, :key service.create_temp_url(directory.key, key, expires, "GET", ) end |