Class: Files::File
- Inherits:
-
Object
- Object
- Files::File
- Defined in:
- lib/files.com/models/file.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
- #lineno(*_args) ⇒ Object
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #pos ⇒ Object
- #sync ⇒ Object
Class Method Summary collapse
-
.begin_upload(path, params = {}, options = {}) ⇒ Object
Begin file upload.
- .binread(name, *args) ⇒ Object
- .binwrite(name, *args) ⇒ Object
- .chmod(*_args) ⇒ Object
- .chown(*_args) ⇒ Object
- .client(options = {}) ⇒ Object
-
.copy(path, params = {}, options = {}) ⇒ Object
Copy file/folder.
- .copy_stream(*_args) ⇒ Object
-
.create(path, params = {}, options = {}) ⇒ Object
Parameters: path (required) - string - Path to operate on.
-
.delete(path, params = {}, options = {}) ⇒ Object
Parameters: recursive - boolean - If true, will recursively delete folers.
- .destroy(path, params = {}, options = {}) ⇒ Object
- .directory?(path, options = {}) ⇒ Boolean
-
.download(path, params = {}, options = {}) ⇒ Object
Download file.
- .download_file(path, local_path = nil) ⇒ Object
- .exist?(path, options = {}) ⇒ Boolean
- .exists?(path, options = {}) ⇒ Boolean
-
.find(path, params = {}, options = {}) ⇒ Object
Parameters: path (required) - string - Path to operate on.
- .for_fd(*_args) ⇒ Object
- .foreach(name, *args, &block) ⇒ Object
- .from_path(path) ⇒ Object
- .get(path, params = {}, options = {}) ⇒ Object
- .identical?(path1, path2) ⇒ Boolean
- .lstat(path) ⇒ Object
-
.move(path, params = {}, options = {}) ⇒ Object
Move file/folder.
- .mtime(path) ⇒ Object
- .open(path, mode = "r", options = {}, &block) ⇒ Object
- .owned?(_path) ⇒ Boolean
- .pipe(*_args) ⇒ Object
- .popen(*_args) ⇒ Object
- .read(name, *args) ⇒ Object
- .readable?(path) ⇒ Boolean
- .readlines(name, *args) ⇒ Object
- .rename(old_path, new_path) ⇒ Object
- .select(*_args) ⇒ Object
- .stat(path) ⇒ Object
- .sysopen(*_args) ⇒ Object
- .try_convert(*_args) ⇒ Object
- .unlink(*paths) ⇒ Object
-
.update(path, params = {}, options = {}) ⇒ Object
Parameters: provided_mtime - string - Modified time of file.
- .upload_chunks(io, path, options, upload = nil, etags = [], params: {}) ⇒ Object
- .upload_file(path, destination = nil, options = {}, params: {}) ⇒ Object
- .write(*_args) ⇒ Object
- .zero?(path) ⇒ Boolean
Instance Method Summary collapse
-
#action ⇒ Object
string - The action to perform.
- #action=(value) ⇒ Object
- #advise(*_args) ⇒ Object
- #atime ⇒ Object
- #autoclose=(*_args) ⇒ Object
- #autoclose?(*_args) ⇒ Boolean
-
#begin_upload(params = {}) ⇒ Object
Begin file upload.
- #binmode ⇒ Object
- #binmode? ⇒ Boolean
- #birthtime ⇒ Object
- #bytes ⇒ Object
- #chars ⇒ Object
- #chmod(*_args) ⇒ Object
- #chown(*_args) ⇒ Object
- #client ⇒ Object
- #close ⇒ Object
- #close_on_exec=(*args) ⇒ Object
- #close_on_exec?(*args) ⇒ Boolean
- #close_read(*args) ⇒ Object
- #close_write(*args) ⇒ Object
- #closed?(*args) ⇒ Boolean
- #codepoints(*args, &block) ⇒ Object
-
#copy(params = {}) ⇒ Object
Copy file/folder.
-
#crc32 ⇒ Object
string - File CRC32 checksum.
- #crc32=(value) ⇒ Object
-
#created_at ⇒ Object
date-time - File created date/time.
- #ctime(*_args) ⇒ Object
-
#delete(params = {}) ⇒ Object
Parameters: recursive - boolean - If true, will recursively delete folers.
- #destroy(params = {}) ⇒ Object
-
#display_name ⇒ Object
string - File/Folder display name.
- #display_name=(value) ⇒ Object
-
#download(params = {}) ⇒ Object
Download file.
- #download_content(io, range: []) ⇒ Object
- #download_file(output_file) ⇒ Object
-
#download_uri ⇒ Object
string - Link to download file.
- #download_uri=(value) ⇒ Object
- #download_uri_with_load ⇒ Object
- #each(*args, &block) ⇒ Object
- #each_byte(*args, &block) ⇒ Object
- #each_char(*args, &block) ⇒ Object
- #each_codepoint(*args, &block) ⇒ Object
- #each_line(*args, &block) ⇒ Object
- #empty? ⇒ Boolean
- #eof ⇒ Object
- #eof? ⇒ Boolean
- #external_encoding(*args) ⇒ Object
- #fcntl(*_args) ⇒ Object
- #fdatasync(*_args) ⇒ Object
- #fileno(*_args) ⇒ Object
- #flock(*_args) ⇒ Object
- #flush(*_args) ⇒ Object
- #fsync(*args) ⇒ Object
- #getbyte(*args) ⇒ Object
- #getc(*args) ⇒ Object
- #gets(*args) ⇒ Object
-
#initialize(*args) ⇒ File
constructor
A new instance of File.
- #internal_encoding(*_args) ⇒ Object
- #ioctl(*_args) ⇒ Object
-
#is_locked ⇒ Object
boolean - Is this folder locked and unable to be modified?.
- #is_locked=(value) ⇒ Object
- #isatty(*_args) ⇒ Object
-
#length ⇒ Object
int64 - Length of file.
- #length=(value) ⇒ Object
- #lines(*args, &block) ⇒ Object
- #lstat(*_args) ⇒ Object
-
#md5 ⇒ Object
string - File MD5 checksum.
- #md5=(value) ⇒ Object
-
#mime_type ⇒ Object
string - MIME Type.
- #mime_type=(value) ⇒ Object
-
#mkdir_parents ⇒ Object
boolean - Create parent directories if they do not exist?.
- #mkdir_parents=(value) ⇒ Object
-
#move(params = {}) ⇒ Object
Move file/folder.
-
#mtime ⇒ Object
date-time - File last modified date/time, according to the server.
- #mtime=(value) ⇒ Object
- #mv(destination) ⇒ Object
-
#part ⇒ Object
int64 - Part if uploading a part.
- #part=(value) ⇒ Object
-
#parts ⇒ Object
int64 - How many parts to fetch?.
- #parts=(value) ⇒ Object
-
#path ⇒ Object
string - File/Folder path This must be slash-delimited, but it must neither start nor end with a slash.
- #path=(value) ⇒ Object
-
#permissions ⇒ Object
string - A short string representing the current user’s permissions.
- #permissions=(value) ⇒ Object
- #pid(*_args) ⇒ Object
- #pread(*args) ⇒ Object
-
#preview ⇒ Object
Preview - File preview.
- #preview=(value) ⇒ Object
-
#preview_id ⇒ Object
int64 - File preview ID.
- #preview_id=(value) ⇒ Object
- #print(*args) ⇒ Object
- #printf(*args) ⇒ Object
-
#priority_color ⇒ Object
string - Bookmark/priority color of file/folder.
- #priority_color=(value) ⇒ Object
-
#provided_mtime ⇒ Object
date-time - File last modified date/time, according to the client who set it.
- #provided_mtime=(value) ⇒ Object
- #putc(*args) ⇒ Object
- #puts(*args) ⇒ Object
- #pwrite(*args) ⇒ Object
- #read(*args) ⇒ Object
- #read_io(**options) ⇒ Object
- #read_nonblock(*args) ⇒ Object
- #readbyte(*args) ⇒ Object
- #readchar(*args) ⇒ Object
- #readline(*args) ⇒ Object
- #readlines(*args) ⇒ Object
- #readpartial(*args) ⇒ Object
-
#ref ⇒ Object
string -.
- #ref=(value) ⇒ Object
-
#region ⇒ Object
string - Region location.
- #region=(value) ⇒ Object
- #rename(destination) ⇒ Object
- #reopen(*_args) ⇒ Object
-
#restart ⇒ Object
int64 - File byte offset to restart from.
- #restart=(value) ⇒ Object
- #rewind ⇒ Object
- #save ⇒ Object
- #seek(pos) ⇒ Object
- #set_encoding(*_args) ⇒ Object
-
#size ⇒ Object
int64 - File/Folder size.
- #size=(value) ⇒ Object
- #stat(*_args) ⇒ Object
-
#structure ⇒ Object
string - If copying folder, copy just the structure?.
- #structure=(value) ⇒ Object
- #subfolders_locked=(value) ⇒ Object
-
#subfolders_locked? ⇒ Boolean
boolean - Are subfolders locked and unable to be modified?.
- #sysread(*args) ⇒ Object
- #sysseek(*args) ⇒ Object
- #syswrite(*_args) ⇒ Object
- #tell ⇒ Object
- #to_i(*_args) ⇒ Object
- #to_io(*_args) ⇒ Object
- #to_path(*_args) ⇒ Object
- #truncate(*_args) ⇒ Object
- #tty?(*_args) ⇒ Boolean
-
#type ⇒ Object
string - Type: ‘directory` or `file`.
- #type=(value) ⇒ Object
- #ungetbyte(*_args) ⇒ Object
- #ungetc(*_args) ⇒ Object
-
#update(params = {}) ⇒ Object
Parameters: provided_mtime - string - Modified time of file.
- #upload_file(local_file) ⇒ Object
-
#with_rename ⇒ Object
boolean - Allow file rename instead of overwrite?.
- #with_rename=(value) ⇒ Object
- #write(*args) ⇒ Object
- #write_nonblock(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ File
Returns a new instance of File.
180 181 182 183 184 185 186 187 188 |
# File 'lib/files.com/models/file.rb', line 180 def initialize(*args) @attributes = (args[0].is_a?(Hash) && args[0]) || {} @options = (args[1].is_a?(Hash) && args[1]) @options ||= (args[2].is_a?(Hash) && args[2]) || {} @attributes[:path] = args[0] if args[0].is_a?(String) @mode = args[1] || 'r' if args[1].is_a?(String) @write_io = StringIO.new @bytes_written = 0 end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/files.com/models/file.rb', line 5 def attributes @attributes end |
#lineno(*_args) ⇒ Object
400 401 402 |
# File 'lib/files.com/models/file.rb', line 400 def lineno(*_args) @lineno ||= 0 end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/files.com/models/file.rb', line 6 def mode @mode end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/files.com/models/file.rb', line 5 def @options end |
#pos ⇒ Object
422 423 424 |
# File 'lib/files.com/models/file.rb', line 422 def pos @pos ||= 0 end |
#sync ⇒ Object
502 503 504 |
# File 'lib/files.com/models/file.rb', line 502 def sync @sync ||= false end |
Class Method Details
.begin_upload(path, params = {}, options = {}) ⇒ Object
Begin file upload
Parameters:
mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
with_rename - boolean - Allow file rename instead of overwrite?
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
# File 'lib/files.com/models/file.rb', line 1070 def self.begin_upload(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String) raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/file_actions/begin_upload/#{params[:path]}", :post, params, ) response.data.map do |entity_data| FileUploadPart.new(entity_data, ) end end |
.binread(name, *args) ⇒ Object
8 9 10 |
# File 'lib/files.com/models/file.rb', line 8 def self.binread(name, *args) new(name).read(*args) end |
.binwrite(name, *args) ⇒ Object
12 13 14 |
# File 'lib/files.com/models/file.rb', line 12 def self.binwrite(name, *args) new(name).write(*args) end |
.chmod(*_args) ⇒ Object
16 17 18 |
# File 'lib/files.com/models/file.rb', line 16 def self.chmod(*_args) raise NotImplementedError end |
.chown(*_args) ⇒ Object
20 21 22 |
# File 'lib/files.com/models/file.rb', line 20 def self.chown(*_args) raise NotImplementedError end |
.client(options = {}) ⇒ Object
24 25 26 |
# File 'lib/files.com/models/file.rb', line 24 def self.client( = {}) [:client] || ApiClient.active_client end |
.copy(path, params = {}, options = {}) ⇒ Object
Copy file/folder
Parameters:
destination (required) - string - Copy destination path.
structure - boolean - Copy structure only?
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'lib/files.com/models/file.rb', line 1032 def self.copy(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/copy/#{params[:path]}", :post, params, ) FileAction.new(response.data, ) end |
.copy_stream(*_args) ⇒ Object
28 29 30 |
# File 'lib/files.com/models/file.rb', line 28 def self.copy_stream(*_args) raise NotImplementedError end |
.create(path, params = {}, options = {}) ⇒ Object
Parameters:
path (required) - string - Path to operate on.
action - string - The action to perform. Can be `append`, `attachment`, `end`, `upload`, `put`, or may not exist
etags[etag] (required) - array(string) - etag identifier.
etags[part] (required) - array(int64) - Part number.
length - int64 - Length of file.
mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
provided_mtime - string - User provided modification time.
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Size of file.
structure - string - If copying folder, copy just the structure?
with_rename - boolean - Allow file rename instead of overwrite?
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 |
# File 'lib/files.com/models/file.rb', line 956 def self.create(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].is_a?(String) raise InvalidParameterError.new("Bad parameter: length must be an Integer") if params[:length] and !params[:length].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String) raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String) raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: structure must be an String") if params[:structure] and !params[:structure].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/files/#{params[:path]}", :post, params, ) File.new(response.data, ) end |
.delete(path, params = {}, options = {}) ⇒ Object
Parameters:
recursive - boolean - If true, will recursively delete folers. Otherwise, will error on non-empty folders.
992 993 994 995 996 997 998 999 1000 |
# File 'lib/files.com/models/file.rb', line 992 def self.delete(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{params[:path]}", :delete, params, ) nil end |
.destroy(path, params = {}, options = {}) ⇒ Object
1002 1003 1004 1005 |
# File 'lib/files.com/models/file.rb', line 1002 def self.destroy(path, params = {}, = {}) delete(path, params, ) nil end |
.directory?(path, options = {}) ⇒ Boolean
32 33 34 |
# File 'lib/files.com/models/file.rb', line 32 def self.directory?(path, = {}) find(path, {}, ).type == "directory" end |
.download(path, params = {}, options = {}) ⇒ Object
Download file
Parameters:
action - string - Can be blank, `redirect` or `stat`. If set to `stat`, we will return file information but without a download URL, and without logging a download. If set to `redirect` we will serve a 302 redirect directly to the file. This is used for integrations with Zapier, and is not recommended for most integrations.
preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?
929 930 931 932 933 934 935 936 937 938 939 |
# File 'lib/files.com/models/file.rb', line 929 def self.download(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].is_a?(String) raise InvalidParameterError.new("Bad parameter: preview_size must be an String") if params[:preview_size] and !params[:preview_size].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/files/#{params[:path]}", :get, params, ) File.new(response.data, ) end |
.download_file(path, local_path = nil) ⇒ Object
36 37 38 39 |
# File 'lib/files.com/models/file.rb', line 36 def self.download_file(path, local_path = nil) local_path ||= File.basename(path) new(path).download_file(local_path) end |
.exist?(path, options = {}) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/files.com/models/file.rb', line 41 def self.exist?(path, = {}) find(path, {}, ) true rescue Error => e if e.code == 404 false else raise e end end |
.exists?(path, options = {}) ⇒ Boolean
52 53 54 |
# File 'lib/files.com/models/file.rb', line 52 def self.exists?(path, = {}) exist?(path, ) end |
.find(path, params = {}, options = {}) ⇒ Object
Parameters:
path (required) - string - Path to operate on.
preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 |
# File 'lib/files.com/models/file.rb', line 1012 def self.find(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: preview_size must be an String") if params[:preview_size] and !params[:preview_size].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/file_actions/metadata/#{params[:path]}", :get, params, ) File.new(response.data, ) end |
.for_fd(*_args) ⇒ Object
56 57 58 |
# File 'lib/files.com/models/file.rb', line 56 def self.for_fd(*_args) raise NotImplementedError end |
.foreach(name, *args, &block) ⇒ Object
60 61 62 |
# File 'lib/files.com/models/file.rb', line 60 def self.foreach(name, *args, &block) new(name).each(*args, &block) end |
.from_path(path) ⇒ Object
64 65 66 |
# File 'lib/files.com/models/file.rb', line 64 def self.from_path(path) File.find(path) end |
.get(path, params = {}, options = {}) ⇒ Object
1023 1024 1025 |
# File 'lib/files.com/models/file.rb', line 1023 def self.get(path, params = {}, = {}) find(path, params, ) end |
.identical?(path1, path2) ⇒ Boolean
68 69 70 |
# File 'lib/files.com/models/file.rb', line 68 def self.identical?(path1, path2) new(path1).crc32 == new(path2).crc32 end |
.lstat(path) ⇒ Object
72 73 74 |
# File 'lib/files.com/models/file.rb', line 72 def self.lstat(path) new(path).stat end |
.move(path, params = {}, options = {}) ⇒ Object
Move file/folder
Parameters:
destination (required) - string - Move destination path.
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/files.com/models/file.rb', line 1048 def self.move(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/move/#{params[:path]}", :post, params, ) FileAction.new(response.data, ) end |
.mtime(path) ⇒ Object
76 77 78 |
# File 'lib/files.com/models/file.rb', line 76 def self.mtime(path) new(path).mtime end |
.open(path, mode = "r", options = {}, &block) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/files.com/models/file.rb', line 80 def self.open(path, mode = "r", = {}, &block) file = new(path, mode, ) if block yield file file.close end file end |
.owned?(_path) ⇒ Boolean
89 90 91 |
# File 'lib/files.com/models/file.rb', line 89 def self.owned?(_path) raise NotImplementedError end |
.pipe(*_args) ⇒ Object
93 94 95 |
# File 'lib/files.com/models/file.rb', line 93 def self.pipe(*_args) raise NotImplementedError end |
.popen(*_args) ⇒ Object
97 98 99 |
# File 'lib/files.com/models/file.rb', line 97 def self.popen(*_args) raise NotImplementedError end |
.read(name, *args) ⇒ Object
101 102 103 |
# File 'lib/files.com/models/file.rb', line 101 def self.read(name, *args) new(name).read(*args) end |
.readable?(path) ⇒ Boolean
105 106 107 |
# File 'lib/files.com/models/file.rb', line 105 def self.readable?(path) new(path).stat..include?("read") end |
.readlines(name, *args) ⇒ Object
109 110 111 |
# File 'lib/files.com/models/file.rb', line 109 def self.readlines(name, *args) new(name).readlines(*args) end |
.rename(old_path, new_path) ⇒ Object
113 114 115 |
# File 'lib/files.com/models/file.rb', line 113 def self.rename(old_path, new_path) FileAction.move(old_path, destination: new_path) end |
.select(*_args) ⇒ Object
117 118 119 |
# File 'lib/files.com/models/file.rb', line 117 def self.select(*_args) raise NotImplementedError end |
.stat(path) ⇒ Object
121 122 123 |
# File 'lib/files.com/models/file.rb', line 121 def self.stat(path) new(path).stat end |
.sysopen(*_args) ⇒ Object
125 126 127 |
# File 'lib/files.com/models/file.rb', line 125 def self.sysopen(*_args) raise NotImplementedError end |
.try_convert(*_args) ⇒ Object
129 130 131 |
# File 'lib/files.com/models/file.rb', line 129 def self.try_convert(*_args) raise NotImplementedError end |
.unlink(*paths) ⇒ Object
133 134 135 |
# File 'lib/files.com/models/file.rb', line 133 def self.unlink(*paths) paths.map { |p| delete(p) } end |
.update(path, params = {}, options = {}) ⇒ Object
Parameters:
provided_mtime - string - Modified time of file.
priority_color - string - Priority/Bookmark color of file.
978 979 980 981 982 983 984 985 986 987 988 |
# File 'lib/files.com/models/file.rb', line 978 def self.update(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String) raise InvalidParameterError.new("Bad parameter: priority_color must be an String") if params[:priority_color] and !params[:priority_color].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/files/#{params[:path]}", :patch, params, ) File.new(response.data, ) end |
.upload_chunks(io, path, options, upload = nil, etags = [], params: {}) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/files.com/models/file.rb', line 137 def self.upload_chunks(io, path, , upload = nil, = [], params: {}) ||= [] bytes_written = 0 request_parts = [:size] && [:size] < 5.megabytes ? 1 : 5 loop do begin_upload = File.begin_upload(path, params.merge(ref: upload&.ref, parts: request_parts, part: (upload&.part_number || 0) + 1), ) if begin_upload.nil? || begin_upload.empty? upload = begin_upload.is_a?(Enumerable) ? begin_upload.shift : begin_upload buf = io.read(upload.partsize) || "" bytes_written += buf.length method = upload.http_method.downcase.to_sym response = client().remote_request(method, upload.upload_uri, { 'Content-Length': buf.length.to_s, 'Content-Type': 'application/octet-stream' }, buf) << { etag: response.headers["ETag"], part: upload.part_number } return upload, , bytes_written if io.eof? end end |
.upload_file(path, destination = nil, options = {}, params: {}) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/files.com/models/file.rb', line 153 def self.upload_file(path, destination = nil, = {}, params: {}) local_file = ::File.open(path, 'r') destination ||= File.basename(path) params[:size] ||= local_file.size upload, = upload_chunks(local_file, destination, , params: params) params = { action: "end", etags: , provided_mtime: local_file.mtime.to_s, ref: upload.ref, size: local_file.size } create(destination, params, ) ensure local_file.close end |
.write(*_args) ⇒ Object
172 173 174 |
# File 'lib/files.com/models/file.rb', line 172 def self.write(*_args) raise NotImplementedError end |
.zero?(path) ⇒ Boolean
176 177 178 |
# File 'lib/files.com/models/file.rb', line 176 def self.zero?(path) new(path).empty? end |
Instance Method Details
#action ⇒ Object
string - The action to perform. Can be ‘append`, `attachment`, `end`, `upload`, `put`, or may not exist
727 728 729 |
# File 'lib/files.com/models/file.rb', line 727 def action @attributes[:action] end |
#action=(value) ⇒ Object
731 732 733 |
# File 'lib/files.com/models/file.rb', line 731 def action=(value) @attributes[:action] = value end |
#advise(*_args) ⇒ Object
190 |
# File 'lib/files.com/models/file.rb', line 190 def advise(*_args); end |
#atime ⇒ Object
192 193 194 |
# File 'lib/files.com/models/file.rb', line 192 def atime mtime end |
#autoclose=(*_args) ⇒ Object
196 |
# File 'lib/files.com/models/file.rb', line 196 def autoclose=(*_args); end |
#autoclose?(*_args) ⇒ Boolean
198 |
# File 'lib/files.com/models/file.rb', line 198 def autoclose?(*_args); end |
#begin_upload(params = {}) ⇒ Object
Begin file upload
Parameters:
mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
with_rename - boolean - Allow file rename instead of overwrite?
901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
# File 'lib/files.com/models/file.rb', line 901 def begin_upload(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String) raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/file_actions/begin_upload/#{@attributes[:path]}", :post, params, @options) end |
#binmode ⇒ Object
200 201 202 |
# File 'lib/files.com/models/file.rb', line 200 def binmode binmode? end |
#binmode? ⇒ Boolean
204 205 206 |
# File 'lib/files.com/models/file.rb', line 204 def binmode? true end |
#birthtime ⇒ Object
208 209 210 |
# File 'lib/files.com/models/file.rb', line 208 def birthtime raise NotImplementedError end |
#bytes ⇒ Object
212 213 214 |
# File 'lib/files.com/models/file.rb', line 212 def bytes read_io.bytes end |
#chars ⇒ Object
216 217 218 |
# File 'lib/files.com/models/file.rb', line 216 def chars read_io.chars end |
#chmod(*_args) ⇒ Object
220 221 222 |
# File 'lib/files.com/models/file.rb', line 220 def chmod(*_args) raise NotImplementedError end |
#chown(*_args) ⇒ Object
224 225 226 |
# File 'lib/files.com/models/file.rb', line 224 def chown(*_args) raise NotImplementedError end |
#client ⇒ Object
228 229 230 |
# File 'lib/files.com/models/file.rb', line 228 def client [:client] || ApiClient.active_client end |
#close ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/files.com/models/file.rb', line 232 def close flush if @upload = { action: "end", etags: @etags, provided_mtime: Time.now.to_s, ref: @upload.ref, size: @bytes_written } file = File.create(path, , @options) @attributes = file.attributes @upload = nil end @write_io.close end |
#close_on_exec=(*args) ⇒ Object
255 256 257 |
# File 'lib/files.com/models/file.rb', line 255 def close_on_exec=(*args) @write_io.close_on_exec = *args end |
#close_on_exec?(*args) ⇒ Boolean
251 252 253 |
# File 'lib/files.com/models/file.rb', line 251 def close_on_exec?(*args) @write_io.close_on_exec? *args end |
#close_read(*args) ⇒ Object
259 260 261 |
# File 'lib/files.com/models/file.rb', line 259 def close_read(*args) @write_io.close_read *args end |
#close_write(*args) ⇒ Object
263 264 265 |
# File 'lib/files.com/models/file.rb', line 263 def close_write(*args) @write_io.close_write *args end |
#closed?(*args) ⇒ Boolean
267 268 269 |
# File 'lib/files.com/models/file.rb', line 267 def closed?(*args) @write_io.closed? *args end |
#codepoints(*args, &block) ⇒ Object
271 272 273 |
# File 'lib/files.com/models/file.rb', line 271 def codepoints(*args, &block) @write_io.codepoints *args, &block end |
#copy(params = {}) ⇒ Object
Copy file/folder
Parameters:
destination (required) - string - Copy destination path.
structure - boolean - Copy structure only?
863 864 865 866 867 868 869 870 871 872 873 |
# File 'lib/files.com/models/file.rb', line 863 def copy(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] Api.send_request("/file_actions/copy/#{@attributes[:path]}", :post, params, @options) end |
#crc32 ⇒ Object
string - File CRC32 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
628 629 630 |
# File 'lib/files.com/models/file.rb', line 628 def crc32 @attributes[:crc32] end |
#crc32=(value) ⇒ Object
632 633 634 |
# File 'lib/files.com/models/file.rb', line 632 def crc32=(value) @attributes[:crc32] = value end |
#created_at ⇒ Object
date-time - File created date/time
605 606 607 |
# File 'lib/files.com/models/file.rb', line 605 def created_at @attributes[:created_at] end |
#ctime(*_args) ⇒ Object
275 276 277 |
# File 'lib/files.com/models/file.rb', line 275 def ctime(*_args) mtime end |
#delete(params = {}) ⇒ Object
Parameters:
recursive - boolean - If true, will recursively delete folers. Otherwise, will error on non-empty folders.
843 844 845 846 847 848 849 850 851 |
# File 'lib/files.com/models/file.rb', line 843 def delete(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{@attributes[:path]}", :delete, params, @options) end |
#destroy(params = {}) ⇒ Object
853 854 855 856 |
# File 'lib/files.com/models/file.rb', line 853 def destroy(params = {}) delete(params) nil end |
#display_name ⇒ Object
string - File/Folder display name
578 579 580 |
# File 'lib/files.com/models/file.rb', line 578 def display_name @attributes[:display_name] end |
#display_name=(value) ⇒ Object
582 583 584 |
# File 'lib/files.com/models/file.rb', line 582 def display_name=(value) @attributes[:display_name] = value end |
#download(params = {}) ⇒ Object
Download file
Parameters:
action - string - Can be blank, `redirect` or `stat`. If set to `stat`, we will return file information but without a download URL, and without logging a download. If set to `redirect` we will serve a 302 redirect directly to the file. This is used for integrations with Zapier, and is not recommended for most integrations.
preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?
814 815 816 817 818 819 820 821 822 823 824 |
# File 'lib/files.com/models/file.rb', line 814 def download(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].is_a?(String) raise InvalidParameterError.new("Bad parameter: preview_size must be an String") if params[:preview_size] and !params[:preview_size].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{@attributes[:path]}", :get, params, @options) end |
#download_content(io, range: []) ⇒ Object
293 294 295 |
# File 'lib/files.com/models/file.rb', line 293 def download_content(io, range: []) Files::ApiClient.download_client.stream_download(download_uri_with_load, io, range) end |
#download_file(output_file) ⇒ Object
287 288 289 290 291 |
# File 'lib/files.com/models/file.rb', line 287 def download_file(output_file) ::File.open(output_file, 'wb') do |file| download_content(file) end end |
#download_uri ⇒ Object
string - Link to download file. Provided only in response to a download request.
691 692 693 |
# File 'lib/files.com/models/file.rb', line 691 def download_uri @attributes[:download_uri] end |
#download_uri=(value) ⇒ Object
695 696 697 |
# File 'lib/files.com/models/file.rb', line 695 def download_uri=(value) @attributes[:download_uri] = value end |
#download_uri_with_load ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/files.com/models/file.rb', line 279 def download_uri_with_load return download_uri if download_uri file = File.download(path, {}, @options) @attributes = file.attributes download_uri end |
#each(*args, &block) ⇒ Object
297 298 299 |
# File 'lib/files.com/models/file.rb', line 297 def each(*args, &block) read_io.each *args, &block end |
#each_byte(*args, &block) ⇒ Object
301 302 303 |
# File 'lib/files.com/models/file.rb', line 301 def each_byte(*args, &block) read_io.each_byte *args, &block end |
#each_char(*args, &block) ⇒ Object
305 306 307 |
# File 'lib/files.com/models/file.rb', line 305 def each_char(*args, &block) read_io.each_char *args, &block end |
#each_codepoint(*args, &block) ⇒ Object
309 310 311 |
# File 'lib/files.com/models/file.rb', line 309 def each_codepoint(*args, &block) read_io.each_codepoint *args, &block end |
#each_line(*args, &block) ⇒ Object
313 314 315 |
# File 'lib/files.com/models/file.rb', line 313 def each_line(*args, &block) each(*args, &block) end |
#empty? ⇒ Boolean
317 318 319 |
# File 'lib/files.com/models/file.rb', line 317 def empty? size == 0 end |
#eof ⇒ Object
321 322 323 |
# File 'lib/files.com/models/file.rb', line 321 def eof eof? end |
#eof? ⇒ Boolean
325 326 327 |
# File 'lib/files.com/models/file.rb', line 325 def eof? @write_io.eof? end |
#external_encoding(*args) ⇒ Object
329 330 331 |
# File 'lib/files.com/models/file.rb', line 329 def external_encoding(*args) internal_encoding *args end |
#fcntl(*_args) ⇒ Object
333 334 335 |
# File 'lib/files.com/models/file.rb', line 333 def fcntl(*_args) raise NotImplementedError end |
#fdatasync(*_args) ⇒ Object
337 338 339 |
# File 'lib/files.com/models/file.rb', line 337 def fdatasync(*_args) flush end |
#fileno(*_args) ⇒ Object
341 342 343 |
# File 'lib/files.com/models/file.rb', line 341 def fileno(*_args) id end |
#flock(*_args) ⇒ Object
345 346 347 |
# File 'lib/files.com/models/file.rb', line 345 def flock(*_args) raise NotImplementedError end |
#flush(*_args) ⇒ Object
349 350 351 352 353 354 355 356 357 358 |
# File 'lib/files.com/models/file.rb', line 349 def flush(*_args) if mode.include? "w" @write_io.rewind if @write_io.is_a?(StringIO) @upload, @etags, bytes_written = File.upload_chunks(@write_io, path, , @upload, @etags, params: @attributes) @bytes_written += bytes_written elsif mode.include? "a" raise NotImplementedError end end |
#fsync(*args) ⇒ Object
360 361 362 |
# File 'lib/files.com/models/file.rb', line 360 def fsync(*args) flush *args end |
#getbyte(*args) ⇒ Object
364 365 366 |
# File 'lib/files.com/models/file.rb', line 364 def getbyte(*args) read_io.getbyte *args end |
#getc(*args) ⇒ Object
368 369 370 |
# File 'lib/files.com/models/file.rb', line 368 def getc(*args) read_io.getc *args end |
#gets(*args) ⇒ Object
372 373 374 |
# File 'lib/files.com/models/file.rb', line 372 def gets(*args) read_io.gets *args end |
#internal_encoding(*_args) ⇒ Object
388 389 390 |
# File 'lib/files.com/models/file.rb', line 388 def internal_encoding(*_args) "".encoding end |
#ioctl(*_args) ⇒ Object
392 393 394 |
# File 'lib/files.com/models/file.rb', line 392 def ioctl(*_args) raise NotImplementedError end |
#is_locked ⇒ Object
boolean - Is this folder locked and unable to be modified?
682 683 684 |
# File 'lib/files.com/models/file.rb', line 682 def is_locked @attributes[:is_locked] end |
#is_locked=(value) ⇒ Object
686 687 688 |
# File 'lib/files.com/models/file.rb', line 686 def is_locked=(value) @attributes[:is_locked] = value end |
#isatty(*_args) ⇒ Object
396 397 398 |
# File 'lib/files.com/models/file.rb', line 396 def isatty(*_args) false end |
#length ⇒ Object
int64 - Length of file.
736 737 738 |
# File 'lib/files.com/models/file.rb', line 736 def length @attributes[:length] end |
#length=(value) ⇒ Object
740 741 742 |
# File 'lib/files.com/models/file.rb', line 740 def length=(value) @attributes[:length] = value end |
#lines(*args, &block) ⇒ Object
406 407 408 |
# File 'lib/files.com/models/file.rb', line 406 def lines(*args, &block) each_line *args, &block end |
#lstat(*_args) ⇒ Object
410 411 412 |
# File 'lib/files.com/models/file.rb', line 410 def lstat(*_args) stats end |
#md5 ⇒ Object
string - File MD5 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
637 638 639 |
# File 'lib/files.com/models/file.rb', line 637 def md5 @attributes[:md5] end |
#md5=(value) ⇒ Object
641 642 643 |
# File 'lib/files.com/models/file.rb', line 641 def md5=(value) @attributes[:md5] = value end |
#mime_type ⇒ Object
string - MIME Type. This is determined by the filename extension and is not stored separately internally.
646 647 648 |
# File 'lib/files.com/models/file.rb', line 646 def mime_type @attributes[:mime_type] end |
#mime_type=(value) ⇒ Object
650 651 652 |
# File 'lib/files.com/models/file.rb', line 650 def mime_type=(value) @attributes[:mime_type] = value end |
#mkdir_parents ⇒ Object
boolean - Create parent directories if they do not exist?
745 746 747 |
# File 'lib/files.com/models/file.rb', line 745 def mkdir_parents @attributes[:mkdir_parents] end |
#mkdir_parents=(value) ⇒ Object
749 750 751 |
# File 'lib/files.com/models/file.rb', line 749 def mkdir_parents=(value) @attributes[:mkdir_parents] = value end |
#move(params = {}) ⇒ Object
Move file/folder
Parameters:
destination (required) - string - Move destination path.
879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/files.com/models/file.rb', line 879 def move(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] Api.send_request("/file_actions/move/#{@attributes[:path]}", :post, params, @options) end |
#mtime ⇒ Object
date-time - File last modified date/time, according to the server. This is the timestamp of the last Files.com operation of the file, regardless of what modified timestamp was sent.
610 611 612 |
# File 'lib/files.com/models/file.rb', line 610 def mtime @attributes[:mtime] end |
#mtime=(value) ⇒ Object
614 615 616 |
# File 'lib/files.com/models/file.rb', line 614 def mtime=(value) @attributes[:mtime] = value end |
#mv(destination) ⇒ Object
414 415 416 |
# File 'lib/files.com/models/file.rb', line 414 def mv(destination) File.move(path, destination) end |
#part ⇒ Object
int64 - Part if uploading a part.
754 755 756 |
# File 'lib/files.com/models/file.rb', line 754 def part @attributes[:part] end |
#part=(value) ⇒ Object
758 759 760 |
# File 'lib/files.com/models/file.rb', line 758 def part=(value) @attributes[:part] = value end |
#parts ⇒ Object
int64 - How many parts to fetch?
763 764 765 |
# File 'lib/files.com/models/file.rb', line 763 def parts @attributes[:parts] end |
#parts=(value) ⇒ Object
767 768 769 |
# File 'lib/files.com/models/file.rb', line 767 def parts=(value) @attributes[:parts] = value end |
#path ⇒ Object
string - File/Folder path This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
569 570 571 |
# File 'lib/files.com/models/file.rb', line 569 def path @attributes[:path] end |
#path=(value) ⇒ Object
573 574 575 |
# File 'lib/files.com/models/file.rb', line 573 def path=(value) @attributes[:path] = value end |
#permissions ⇒ Object
string - A short string representing the current user’s permissions. Can be ‘r` (Read),`w` (Write),`d` (Delete), `l` (List) or any combination
664 665 666 |
# File 'lib/files.com/models/file.rb', line 664 def @attributes[:permissions] end |
#permissions=(value) ⇒ Object
668 669 670 |
# File 'lib/files.com/models/file.rb', line 668 def (value) @attributes[:permissions] = value end |
#pid(*_args) ⇒ Object
418 419 420 |
# File 'lib/files.com/models/file.rb', line 418 def pid(*_args) Process.pid end |
#pread(*args) ⇒ Object
426 427 428 |
# File 'lib/files.com/models/file.rb', line 426 def pread(*args) read_io.pread *args end |
#preview ⇒ Object
Preview - File preview
718 719 720 |
# File 'lib/files.com/models/file.rb', line 718 def preview @attributes[:preview] end |
#preview=(value) ⇒ Object
722 723 724 |
# File 'lib/files.com/models/file.rb', line 722 def preview=(value) @attributes[:preview] = value end |
#preview_id ⇒ Object
int64 - File preview ID
709 710 711 |
# File 'lib/files.com/models/file.rb', line 709 def preview_id @attributes[:preview_id] end |
#preview_id=(value) ⇒ Object
713 714 715 |
# File 'lib/files.com/models/file.rb', line 713 def preview_id=(value) @attributes[:preview_id] = value end |
#print(*args) ⇒ Object
430 431 432 |
# File 'lib/files.com/models/file.rb', line 430 def print(*args) @write_io.print *args end |
#printf(*args) ⇒ Object
434 435 436 |
# File 'lib/files.com/models/file.rb', line 434 def printf(*args) @write_io.printf *args end |
#priority_color ⇒ Object
string - Bookmark/priority color of file/folder
700 701 702 |
# File 'lib/files.com/models/file.rb', line 700 def priority_color @attributes[:priority_color] end |
#priority_color=(value) ⇒ Object
704 705 706 |
# File 'lib/files.com/models/file.rb', line 704 def priority_color=(value) @attributes[:priority_color] = value end |
#provided_mtime ⇒ Object
date-time - File last modified date/time, according to the client who set it. Files.com allows desktop, FTP, SFTP, and WebDAV clients to set modified at times. This allows Desktop<->Cloud syncing to preserve modified at times.
619 620 621 |
# File 'lib/files.com/models/file.rb', line 619 def provided_mtime @attributes[:provided_mtime] end |
#provided_mtime=(value) ⇒ Object
623 624 625 |
# File 'lib/files.com/models/file.rb', line 623 def provided_mtime=(value) @attributes[:provided_mtime] = value end |
#putc(*args) ⇒ Object
438 439 440 |
# File 'lib/files.com/models/file.rb', line 438 def putc(*args) @write_io.putc *args end |
#puts(*args) ⇒ Object
442 443 444 |
# File 'lib/files.com/models/file.rb', line 442 def puts(*args) @write_io.puts *args end |
#pwrite(*args) ⇒ Object
446 447 448 |
# File 'lib/files.com/models/file.rb', line 446 def pwrite(*args) @write_io.pwrite *args end |
#read(*args) ⇒ Object
450 451 452 |
# File 'lib/files.com/models/file.rb', line 450 def read(*args) read_io.read *args end |
#read_io(**options) ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/files.com/models/file.rb', line 376 def read_io(**) @read_io ||= begin r, w = SizableIO.pipe Thread.new do download_content(w, **) ensure w.close end r.wait!(5) end end |
#read_nonblock(*args) ⇒ Object
454 455 456 |
# File 'lib/files.com/models/file.rb', line 454 def read_nonblock(*args) read_io.read_nonblock *args end |
#readbyte(*args) ⇒ Object
458 459 460 |
# File 'lib/files.com/models/file.rb', line 458 def readbyte(*args) read_io.readbyte *args end |
#readchar(*args) ⇒ Object
462 463 464 |
# File 'lib/files.com/models/file.rb', line 462 def readchar(*args) read_io.readchar *args end |
#readline(*args) ⇒ Object
466 467 468 |
# File 'lib/files.com/models/file.rb', line 466 def readline(*args) read_io.readline *args end |
#readlines(*args) ⇒ Object
470 471 472 |
# File 'lib/files.com/models/file.rb', line 470 def readlines(*args) io.readlines(*args) end |
#readpartial(*args) ⇒ Object
474 475 476 |
# File 'lib/files.com/models/file.rb', line 474 def readpartial(*args) read_io.readpartial *args end |
#ref ⇒ Object
string -
772 773 774 |
# File 'lib/files.com/models/file.rb', line 772 def ref @attributes[:ref] end |
#ref=(value) ⇒ Object
776 777 778 |
# File 'lib/files.com/models/file.rb', line 776 def ref=(value) @attributes[:ref] = value end |
#region ⇒ Object
string - Region location
655 656 657 |
# File 'lib/files.com/models/file.rb', line 655 def region @attributes[:region] end |
#region=(value) ⇒ Object
659 660 661 |
# File 'lib/files.com/models/file.rb', line 659 def region=(value) @attributes[:region] = value end |
#rename(destination) ⇒ Object
478 479 480 |
# File 'lib/files.com/models/file.rb', line 478 def rename(destination) File.rename(path, destination) end |
#reopen(*_args) ⇒ Object
482 483 484 |
# File 'lib/files.com/models/file.rb', line 482 def reopen(*_args) raise NotImplementedError end |
#restart ⇒ Object
int64 - File byte offset to restart from.
781 782 783 |
# File 'lib/files.com/models/file.rb', line 781 def restart @attributes[:restart] end |
#restart=(value) ⇒ Object
785 786 787 |
# File 'lib/files.com/models/file.rb', line 785 def restart=(value) @attributes[:restart] = value end |
#rewind ⇒ Object
486 487 488 |
# File 'lib/files.com/models/file.rb', line 486 def rewind @pos = 0 end |
#save ⇒ Object
916 917 918 919 920 |
# File 'lib/files.com/models/file.rb', line 916 def save new_obj = File.create(path, @attributes, @options) @attributes = new_obj.attributes true end |
#seek(pos) ⇒ Object
490 491 492 |
# File 'lib/files.com/models/file.rb', line 490 def seek(pos) @pos = pos end |
#set_encoding(*_args) ⇒ Object
494 495 496 |
# File 'lib/files.com/models/file.rb', line 494 def set_encoding(*_args) raise NotImplementedError end |
#size ⇒ Object
int64 - File/Folder size
596 597 598 |
# File 'lib/files.com/models/file.rb', line 596 def size @attributes[:size] end |
#size=(value) ⇒ Object
600 601 602 |
# File 'lib/files.com/models/file.rb', line 600 def size=(value) @attributes[:size] = value end |
#stat(*_args) ⇒ Object
498 499 500 |
# File 'lib/files.com/models/file.rb', line 498 def stat(*_args) stats end |
#structure ⇒ Object
string - If copying folder, copy just the structure?
790 791 792 |
# File 'lib/files.com/models/file.rb', line 790 def structure @attributes[:structure] end |
#structure=(value) ⇒ Object
794 795 796 |
# File 'lib/files.com/models/file.rb', line 794 def structure=(value) @attributes[:structure] = value end |
#subfolders_locked=(value) ⇒ Object
677 678 679 |
# File 'lib/files.com/models/file.rb', line 677 def subfolders_locked=(value) @attributes[:subfolders_locked?] = value end |
#subfolders_locked? ⇒ Boolean
boolean - Are subfolders locked and unable to be modified?
673 674 675 |
# File 'lib/files.com/models/file.rb', line 673 def subfolders_locked? @attributes[:subfolders_locked?] end |
#sysread(*args) ⇒ Object
506 507 508 |
# File 'lib/files.com/models/file.rb', line 506 def sysread(*args) read *args end |
#sysseek(*args) ⇒ Object
510 511 512 |
# File 'lib/files.com/models/file.rb', line 510 def sysseek(*args) seek *args end |
#syswrite(*_args) ⇒ Object
514 515 516 |
# File 'lib/files.com/models/file.rb', line 514 def syswrite(*_args) raise NotImplementedError end |
#tell ⇒ Object
518 519 520 |
# File 'lib/files.com/models/file.rb', line 518 def tell pos end |
#to_i(*_args) ⇒ Object
522 523 524 |
# File 'lib/files.com/models/file.rb', line 522 def to_i(*_args) fileno end |
#to_io(*_args) ⇒ Object
526 527 528 |
# File 'lib/files.com/models/file.rb', line 526 def to_io(*_args) @write_io end |
#to_path(*_args) ⇒ Object
530 531 532 |
# File 'lib/files.com/models/file.rb', line 530 def to_path(*_args) path end |
#truncate(*_args) ⇒ Object
534 535 536 |
# File 'lib/files.com/models/file.rb', line 534 def truncate(*_args) raise NotImplementedError end |
#tty?(*_args) ⇒ Boolean
538 539 540 |
# File 'lib/files.com/models/file.rb', line 538 def tty?(*_args) false end |
#type ⇒ Object
string - Type: ‘directory` or `file`.
587 588 589 |
# File 'lib/files.com/models/file.rb', line 587 def type @attributes[:type] end |
#type=(value) ⇒ Object
591 592 593 |
# File 'lib/files.com/models/file.rb', line 591 def type=(value) @attributes[:type] = value end |
#ungetbyte(*_args) ⇒ Object
542 543 544 |
# File 'lib/files.com/models/file.rb', line 542 def ungetbyte(*_args) raise NotImplementedError end |
#ungetc(*_args) ⇒ Object
546 547 548 |
# File 'lib/files.com/models/file.rb', line 546 def ungetc(*_args) raise NotImplementedError end |
#update(params = {}) ⇒ Object
Parameters:
provided_mtime - string - Modified time of file.
priority_color - string - Priority/Bookmark color of file.
829 830 831 832 833 834 835 836 837 838 839 |
# File 'lib/files.com/models/file.rb', line 829 def update(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String) raise InvalidParameterError.new("Bad parameter: priority_color must be an String") if params[:priority_color] and !params[:priority_color].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{@attributes[:path]}", :patch, params, @options) end |
#upload_file(local_file) ⇒ Object
550 551 552 |
# File 'lib/files.com/models/file.rb', line 550 def upload_file(local_file) File.upload_file(local_file.path, params: @attributes) end |
#with_rename ⇒ Object
boolean - Allow file rename instead of overwrite?
799 800 801 |
# File 'lib/files.com/models/file.rb', line 799 def with_rename @attributes[:with_rename] end |
#with_rename=(value) ⇒ Object
803 804 805 |
# File 'lib/files.com/models/file.rb', line 803 def with_rename=(value) @attributes[:with_rename] = value end |
#write(*args) ⇒ Object
554 555 556 557 558 559 560 561 562 |
# File 'lib/files.com/models/file.rb', line 554 def write(*args) @mode ||= 'w' if args[0].respond_to?(:read) flush if @write_io.size > 0 # rubocop:disable Style/ZeroLengthPredicate @write_io = args[0] else @write_io.write *args end end |
#write_nonblock(*args) ⇒ Object
564 565 566 |
# File 'lib/files.com/models/file.rb', line 564 def write_nonblock(*args) @write_io.write_nonblock *args end |