Class: Fog::Storage::GoogleJSON::File
- Inherits:
-
Model
- Object
- Model
- Fog::Storage::GoogleJSON::File
- Defined in:
- lib/fog/storage/google_json/models/file.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
-
#body ⇒ Object
TODO: Implement object ACLs def acl=(new_acl) valid_acls = [“private”, “projectPrivate”, “bucketOwnerFullControl”, “bucketOwnerRead”, “authenticatedRead”, “publicRead”] unless valid_acls.include?(new_acl) raise ArgumentError.new(“acl must be one of [#’)]”) end @acl = new_acl end.
- #body=(new_body) ⇒ Object
- #copy(target_directory_key, target_file_key, options = {}) ⇒ Object
- #destroy ⇒ Object
- #metadata=(new_metadata) ⇒ Object
- #owner=(new_owner) ⇒ Object
- #predefined_acl=(new_acl) ⇒ Object
- #public=(new_public) ⇒ Object
- #public_url ⇒ Object
- #save(options = {}) ⇒ Object
-
#url(expires) ⇒ Object
params : Eg: Time.now to integer value.
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
53 54 55 |
# File 'lib/fog/storage/google_json/models/file.rb', line 53 def directory @directory end |
Instance Method Details
#body ⇒ Object
TODO: Implement object ACLs def acl=(new_acl)
valid_acls = ["private", "projectPrivate", "bucketOwnerFullControl", "bucketOwnerRead", "authenticatedRead", "publicRead"]
unless valid_acls.include?(new_acl)
raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
end
@acl = new_acl
end
45 46 47 |
# File 'lib/fog/storage/google_json/models/file.rb', line 45 def body attributes[:body] ||= last_modified && (file = collection.get(identity)) ? file.body : "" end |
#body=(new_body) ⇒ Object
49 50 51 |
# File 'lib/fog/storage/google_json/models/file.rb', line 49 def body=(new_body) attributes[:body] = new_body end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/fog/storage/google_json/models/file.rb', line 55 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
62 63 64 65 66 67 68 |
# File 'lib/fog/storage/google_json/models/file.rb', line 62 def destroy requires :directory, :key service.delete_object(directory.key, key) true rescue Fog::Errors::NotFound false end |
#metadata=(new_metadata) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/fog/storage/google_json/models/file.rb', line 71 def () if attributes[:metadata].nil? attributes[:metadata] = {} end attributes[:metadata].merge!() end |
#owner=(new_owner) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/fog/storage/google_json/models/file.rb', line 80 def owner=(new_owner) if new_owner attributes[:owner] = { :entity => new_owner["entity"], :entityId => new_owner["entityId"] } end end |
#predefined_acl=(new_acl) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/fog/storage/google_json/models/file.rb', line 29 def predefined_acl=(new_acl) unless @valid_predefined_acls.include?(new_acl) raise ArgumentError.new("acl must be one of [#{@valid_predefined_acls.join(', ')}]") end @predefined_acl = new_acl end |
#public=(new_public) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/fog/storage/google_json/models/file.rb', line 89 def public=(new_public) if new_public @predefined_acl = "publicRead" else @predefined_acl = "private" end new_public end |
#public_url ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fog/storage/google_json/models/file.rb', line 98 def public_url requires :directory, :key acl = service.get_object_acl(directory.key, key).body access_granted = acl["items"].detect { |entry| entry["entity"] == "allUsers" && entry["role"] == "READER" } if access_granted if directory.key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/ "https://#{directory.key}.storage.googleapis.com/#{key}" else "https://storage.googleapis.com/#{directory.key}/#{key}" end end end |
#save(options = {}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fog/storage/google_json/models/file.rb', line 113 def save( = {}) requires :body, :directory, :key if != {} Fog::Logger.deprecation("options param is deprecated, use acl= instead [light_black](#{caller.first})[/]") end ["contentType"] = content_type if content_type ["predefinedAcl"] ||= @predefined_acl if @predefined_acl # predefinedAcl may need to be in parameters ["acl"] ||= @acl if @acl # Not sure if you can provide both acl and predefinedAcl ["cacheControl"] = cache_control if cache_control ["contentDisposition"] = content_disposition if content_disposition ["contentEncoding"] = content_encoding if content_encoding # TODO: Should these hashes be recomputed on changes to file contents? # options["md5Hash"] = content_md5 if content_md5 # options["crc32c"] = crc32c if crc32c ["metadata"] = data = service.put_object(directory.key, key, body, ) merge_attributes(data.headers.reject { |key, _value| %w(contentLength contentType).include?(key) }) 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.
137 138 139 140 |
# File 'lib/fog/storage/google_json/models/file.rb', line 137 def url(expires) requires :key collection.get_https_url(key, expires) end |