class Fog::Brightbox::Storage::File
Attributes
directory[RW]
Public Instance Methods
body()
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 29 def copy(target_directory_key, target_file_key, options = {}) requires :directory, :key options["Content-Type"] ||= content_type if content_type options["Access-Control-Allow-Origin"] ||= access_control_allow_origin if access_control_allow_origin options["Origin"] ||= origin if origin service.copy_object(directory.key, key, target_directory_key, target_file_key, options) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.get(target_file_key) end
destroy()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 39 def destroy requires :directory, :key service.delete_object(directory.key, key) true end
metadata()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 45 def metadata @metadata ||= headers_to_metadata end
owner=(new_owner)
click to toggle source
# 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)
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 58 def public=(new_public) new_public end
public_url()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 75 def public_url requires :key collection.get_url(key) end
save(options = {})
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 80 def save(options = {}) requires :body, :directory, :key options["Content-Type"] = content_type if content_type options["Content-Disposition"] = content_disposition if content_disposition options["Access-Control-Allow-Origin"] = access_control_allow_origin if access_control_allow_origin options["Origin"] = origin if origin options.merge!(metadata_to_headers) data = service.put_object(directory.key, key, body, options) update_attributes_from(data) refresh_metadata self.content_length = Fog::Storage.get_body_size(body) self.content_type ||= Fog::Storage.get_content_type(body) true end
url(expires, options = {})
click to toggle source
Get a url for file.
required attributes: key
@param expires [String] number of seconds (since 1970-01-01 00:00) before url expires @param options [Hash] @return [String] url
# File lib/fog/brightbox/models/storage/file.rb, line 70 def url(expires, options = {}) requires :directory, :key service.create_temp_url(directory.key, key, expires, "GET", options) end
Private Instance Methods
header_mapping()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 124 def header_mapping header_map = metadata.dup header_map.each_pair { |k, _v| header_map[k] = key_to_header(k) } end
header_to_key(opt)
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 115 def header_to_key(opt) opt.gsub(metadata_prefix, "").split("-").map { |k| k[0, 1].downcase + k[1..-1] }.join("_").to_sym end
headers_to_metadata()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 105 def headers_to_metadata key_map = key_mapping Hash[metadata_attributes.map { |k, v| [key_map[k], v] }] end
key_mapping()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 110 def key_mapping key_map = metadata_attributes key_map.each_pair { |k, _v| key_map[k] = header_to_key(k) } end
key_to_header(key)
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 129 def key_to_header(key) metadata_prefix + key.to_s.split(/[-_]/).map(&:capitalize).join("-") end
metadata_attribute?(key)
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 142 def metadata_attribute?(key) key.to_s =~ /^#{metadata_prefix}/ end
metadata_attributes()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 133 def metadata_attributes if last_modified headers = service.head_object(directory.key, key).headers headers.reject! { |k, _v| !metadata_attribute?(k) } else {} end end
metadata_prefix()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 146 def metadata_prefix "X-Object-Meta-" end
metadata_to_headers()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 119 def metadata_to_headers header_map = header_mapping Hash[metadata.map { |k, v| [header_map[k], v] }] end
refresh_metadata()
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 101 def refresh_metadata metadata.reject! { |_k, v| v.nil? } end
update_attributes_from(data)
click to toggle source
# File lib/fog/brightbox/models/storage/file.rb, line 150 def update_attributes_from(data) merge_attributes(data.headers.reject { |key, _value| %w(Content-Length Content-Type).include?(key) }) end