Class: Fog::Storage::GoogleJSON::File
- Inherits:
-
Model
- Object
- Model
- Fog::Storage::GoogleJSON::File
- Defined in:
- lib/fog/storage/google_json/models/file.rb
Constant Summary collapse
- FILE_INSERTABLE_FIELDS =
i( content_type predefined_acl acl cache_control content_disposition content_encoding ).freeze
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
-
#body ⇒ Object
attribute :body.
- #body=(new_body) ⇒ Object
- #copy(target_directory_key, target_file_key, options = {}) ⇒ Object
- #destroy ⇒ Object
- #public_url ⇒ Object
- #save ⇒ Object
-
#url(expires) ⇒ Object
params : Eg: Time.now to integer value.
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
37 38 39 |
# File 'lib/fog/storage/google_json/models/file.rb', line 37 def directory @directory end |
Instance Method Details
#body ⇒ Object
attribute :body
29 30 31 |
# File 'lib/fog/storage/google_json/models/file.rb', line 29 def body last_modified && (file = collection.get(identity)) ? attributes[:body] ||= file.body : attributes[:body] ||= "" end |
#body=(new_body) ⇒ Object
33 34 35 |
# File 'lib/fog/storage/google_json/models/file.rb', line 33 def body=(new_body) attributes[:body] = new_body end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/fog/storage/google_json/models/file.rb', line 39 def copy(target_directory_key, target_file_key, = {}) requires :directory, :key 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
46 47 48 49 50 51 52 53 |
# File 'lib/fog/storage/google_json/models/file.rb', line 46 def destroy requires :directory, :key service.delete_object(directory.key, key) true rescue ::Google::Apis::ClientError => e raise e unless e.status_code == 404 false end |
#public_url ⇒ Object
55 56 57 58 |
# File 'lib/fog/storage/google_json/models/file.rb', line 55 def public_url requires :directory, :key "https://storage.googleapis.com/#{directory.key}/#{key}" end |
#save ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fog/storage/google_json/models/file.rb', line 70 def save requires :body, :directory, :key = Hash[ FILE_INSERTABLE_FIELDS.map { |k| [k, attributes[k]] } .reject { |pair| pair[1].nil? } ] 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) true end |
#url(expires) ⇒ Object
params : Eg: Time.now to integer value.
85 86 87 88 |
# File 'lib/fog/storage/google_json/models/file.rb', line 85 def url(expires) requires :key collection.get_https_url(key, expires) end |