class Fog::Storage::Local::File
Public Instance Methods
body()
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 13 def body attributes[:body] ||= if last_modified collection.get(identity).body else '' end end
body=(new_body)
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 21 def body=(new_body) attributes[:body] = new_body end
content_type()
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 25 def content_type @content_type ||= begin unless (mime_types = ::MIME::Types.of(key)).empty? mime_types.first.content_type end end end
copy(target_directory_key, target_file_key, options={})
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 37 def copy(target_directory_key, target_file_key, options={}) 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()
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 44 def destroy requires :directory, :key ::File.delete(path) if ::File.exist?(path) dirs = path.split(::File::SEPARATOR)[0...-1] dirs.length.times do |index| dir_path = dirs[0..-index].join(::File::SEPARATOR) if dir_path.empty? # path starts with ::File::SEPARATOR next end # don't delete the containing directory or higher if dir_path == service.path_to(directory.key) break end pwd = Dir.pwd if ::File.directory?(dir_path) Dir.chdir(dir_path) if Dir.glob('*').empty? Dir.rmdir(dir_path) end Dir.chdir(pwd) end end true end
directory()
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 33 def directory @directory end
public=(new_public)
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 69 def public=(new_public) new_public end
public_url()
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 73 def public_url requires :directory, :key if service.endpoint escaped_directory = URI.escape(directory.key) escaped_key = URI.escape(key) ::File.join(service.endpoint, escaped_directory, escaped_key) else nil end end
save(options = {})
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 86 def save(options = {}) requires :body, :directory, :key # Once 1.9.3 support is dropped, the following two lines # can be replaced with `File.dirname(path)` dirs = path.split(::File::SEPARATOR)[0...-1] dir_path = dirs.join(::File::SEPARATOR) # Create all directories in file path that do not yet exist FileUtils.mkdir_p(dir_path) if (body.is_a?(::File) || body.is_a?(Tempfile)) && ::File.exist?(body.path) FileUtils.cp(body.path, path) else write_file(path, body) end merge_attributes( :content_length => Fog::Storage.get_body_size(body), :last_modified => ::File.mtime(path) ) true end
Private Instance Methods
directory=(new_directory)
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 112 def directory=(new_directory) @directory = new_directory end
path()
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 116 def path service.path_to(::File.join(directory.key, key)) end
write_file(path, content)
click to toggle source
# File lib/fog/storage/local/models/file.rb, line 120 def write_file(path, content) input_io = StringIO.new(content) if content.is_a?(String) input_io ||= content ::File.open(path, 'wb') do |file| IO.copy_stream(input_io, file) end end