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
- VALID_PREDEFINED_ACLS =
[ "authenticatedRead", "bucketOwnerFullControl", "bucketOwnerRead", "private", "projectPrivate", "publicRead", "publicReadWrite" ].freeze
- FILE_INSERTABLE_FIELDS =
%i( content_type predefined_acl cache_control content_disposition content_encoding metadata ).freeze
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
- #predefined_acl=(new_predefined_acl) ⇒ Object
- #public=(new_public) ⇒ Object
- #public_url ⇒ Object
- #save ⇒ Object
- #uniform=(enable) ⇒ Object
-
#url(expires, options = {}) ⇒ Object
params : Eg: Time.now to integer value.
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
69 70 71 |
# File 'lib/fog/storage/google_json/models/file.rb', line 69 def directory @directory end |
Instance Method Details
#body ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fog/storage/google_json/models/file.rb', line 52 def body return attributes[:body] if attributes.key?(:body) file = collection.get(identity) attributes[:body] = if file file.attributes[:body] else "" end end |
#body=(new_body) ⇒ Object
65 66 67 |
# File 'lib/fog/storage/google_json/models/file.rb', line 65 def body=(new_body) attributes[:body] = new_body end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/fog/storage/google_json/models/file.rb', line 71 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
78 79 80 81 82 83 84 85 |
# File 'lib/fog/storage/google_json/models/file.rb', line 78 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 |
#predefined_acl=(new_predefined_acl) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/fog/storage/google_json/models/file.rb', line 45 def predefined_acl=(new_predefined_acl) unless VALID_PREDEFINED_ACLS.include?(new_predefined_acl) raise ArgumentError.new("acl must be one of [#{VALID_PREDEFINED_ACLS.join(', ')}]") end @predefined_acl = new_predefined_acl end |
#public=(new_public) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fog/storage/google_json/models/file.rb', line 87 def public=(new_public) unless new_public.nil? if new_public @predefined_acl = "publicRead" else @predefined_acl = "projectPrivate" end end new_public end |
#public_url ⇒ Object
98 99 100 101 |
# File 'lib/fog/storage/google_json/models/file.rb', line 98 def public_url requires :directory, :key "https://storage.googleapis.com/#{directory.key}/#{key}" end |
#save ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fog/storage/google_json/models/file.rb', line 112 def save requires :body, :directory, :key = Hash[ FILE_INSERTABLE_FIELDS.map { |k| [k, attributes[k]] } .reject { |pair| pair[1].nil? } ] [:predefined_acl] ||= @predefined_acl unless @uniform 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 |
#uniform=(enable) ⇒ Object
41 42 43 |
# File 'lib/fog/storage/google_json/models/file.rb', line 41 def uniform=(enable) @uniform=enable end |
#url(expires, options = {}) ⇒ Object
params : Eg: Time.now to integer value.
129 130 131 132 |
# File 'lib/fog/storage/google_json/models/file.rb', line 129 def url(expires, = {}) requires :key collection.get_https_url(key, expires, ) end |