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.
178 179 180 181 182 183 184 185 186 |
# File 'lib/files.com/models/file.rb', line 178 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
398 399 400 |
# File 'lib/files.com/models/file.rb', line 398 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
420 421 422 |
# File 'lib/files.com/models/file.rb', line 420 def pos @pos ||= 0 end |
#sync ⇒ Object
500 501 502 |
# File 'lib/files.com/models/file.rb', line 500 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?
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 |
# File 'lib/files.com/models/file.rb', line 1065 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?
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 |
# File 'lib/files.com/models/file.rb', line 1027 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?
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 |
# File 'lib/files.com/models/file.rb', line 952 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.
988 989 990 991 992 993 994 995 996 |
# File 'lib/files.com/models/file.rb', line 988 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] response, = Api.send_request("/files/#{params[:path]}", :delete, params, ) response.data end |
.destroy(path, params = {}, options = {}) ⇒ Object
998 999 1000 |
# File 'lib/files.com/models/file.rb', line 998 def self.destroy(path, params = {}, = {}) delete(path, params, ) 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?
925 926 927 928 929 930 931 932 933 934 935 |
# File 'lib/files.com/models/file.rb', line 925 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?
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/files.com/models/file.rb', line 1007 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
1018 1019 1020 |
# File 'lib/files.com/models/file.rb', line 1018 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.
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File 'lib/files.com/models/file.rb', line 1043 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.
974 975 976 977 978 979 980 981 982 983 984 |
# File 'lib/files.com/models/file.rb', line 974 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 |
# File 'lib/files.com/models/file.rb', line 137 def self.upload_chunks(io, path, , upload = nil, = [], params: {}) ||= [] bytes_written = 0 loop do begin_upload = File.begin_upload(path, params.merge(ref: upload&.ref, part: (upload&.part_number || 0) + 1), ) upload = begin_upload.is_a?(Enumerable) ? begin_upload.first : 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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/files.com/models/file.rb', line 152 def self.upload_file(path, destination = nil, = {}, params: {}) local_file = ::File.open(path, 'r') destination ||= File.basename(path) 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
170 171 172 |
# File 'lib/files.com/models/file.rb', line 170 def self.write(*_args) raise NotImplementedError end |
.zero?(path) ⇒ Boolean
174 175 176 |
# File 'lib/files.com/models/file.rb', line 174 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
725 726 727 |
# File 'lib/files.com/models/file.rb', line 725 def action @attributes[:action] end |
#action=(value) ⇒ Object
729 730 731 |
# File 'lib/files.com/models/file.rb', line 729 def action=(value) @attributes[:action] = value end |
#advise(*_args) ⇒ Object
188 |
# File 'lib/files.com/models/file.rb', line 188 def advise(*_args); end |
#atime ⇒ Object
190 191 192 |
# File 'lib/files.com/models/file.rb', line 190 def atime mtime end |
#autoclose=(*_args) ⇒ Object
194 |
# File 'lib/files.com/models/file.rb', line 194 def autoclose=(*_args); end |
#autoclose?(*_args) ⇒ Boolean
196 |
# File 'lib/files.com/models/file.rb', line 196 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?
898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
# File 'lib/files.com/models/file.rb', line 898 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
198 199 200 |
# File 'lib/files.com/models/file.rb', line 198 def binmode binmode? end |
#binmode? ⇒ Boolean
202 203 204 |
# File 'lib/files.com/models/file.rb', line 202 def binmode? true end |
#birthtime ⇒ Object
206 207 208 |
# File 'lib/files.com/models/file.rb', line 206 def birthtime raise NotImplementedError end |
#bytes ⇒ Object
210 211 212 |
# File 'lib/files.com/models/file.rb', line 210 def bytes read_io.bytes end |
#chars ⇒ Object
214 215 216 |
# File 'lib/files.com/models/file.rb', line 214 def chars read_io.chars end |
#chmod(*_args) ⇒ Object
218 219 220 |
# File 'lib/files.com/models/file.rb', line 218 def chmod(*_args) raise NotImplementedError end |
#chown(*_args) ⇒ Object
222 223 224 |
# File 'lib/files.com/models/file.rb', line 222 def chown(*_args) raise NotImplementedError end |
#client ⇒ Object
226 227 228 |
# File 'lib/files.com/models/file.rb', line 226 def client [:client] || ApiClient.active_client end |
#close ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/files.com/models/file.rb', line 230 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
253 254 255 |
# File 'lib/files.com/models/file.rb', line 253 def close_on_exec=(*args) @write_io.close_on_exec = *args end |
#close_on_exec?(*args) ⇒ Boolean
249 250 251 |
# File 'lib/files.com/models/file.rb', line 249 def close_on_exec?(*args) @write_io.close_on_exec? *args end |
#close_read(*args) ⇒ Object
257 258 259 |
# File 'lib/files.com/models/file.rb', line 257 def close_read(*args) @write_io.close_read *args end |
#close_write(*args) ⇒ Object
261 262 263 |
# File 'lib/files.com/models/file.rb', line 261 def close_write(*args) @write_io.close_write *args end |
#closed?(*args) ⇒ Boolean
265 266 267 |
# File 'lib/files.com/models/file.rb', line 265 def closed?(*args) @write_io.closed? *args end |
#codepoints(*args, &block) ⇒ Object
269 270 271 |
# File 'lib/files.com/models/file.rb', line 269 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?
860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/files.com/models/file.rb', line 860 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.
626 627 628 |
# File 'lib/files.com/models/file.rb', line 626 def crc32 @attributes[:crc32] end |
#crc32=(value) ⇒ Object
630 631 632 |
# File 'lib/files.com/models/file.rb', line 630 def crc32=(value) @attributes[:crc32] = value end |
#created_at ⇒ Object
date-time - File created date/time
603 604 605 |
# File 'lib/files.com/models/file.rb', line 603 def created_at @attributes[:created_at] end |
#ctime(*_args) ⇒ Object
273 274 275 |
# File 'lib/files.com/models/file.rb', line 273 def ctime(*_args) mtime end |
#delete(params = {}) ⇒ Object
Parameters:
recursive - boolean - If true, will recursively delete folers. Otherwise, will error on non-empty folders.
841 842 843 844 845 846 847 848 849 |
# File 'lib/files.com/models/file.rb', line 841 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
851 852 853 |
# File 'lib/files.com/models/file.rb', line 851 def destroy(params = {}) delete(params) end |
#display_name ⇒ Object
string - File/Folder display name
576 577 578 |
# File 'lib/files.com/models/file.rb', line 576 def display_name @attributes[:display_name] end |
#display_name=(value) ⇒ Object
580 581 582 |
# File 'lib/files.com/models/file.rb', line 580 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?
812 813 814 815 816 817 818 819 820 821 822 |
# File 'lib/files.com/models/file.rb', line 812 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
291 292 293 |
# File 'lib/files.com/models/file.rb', line 291 def download_content(io, range: []) Files::ApiClient.download_client.stream_download(download_uri_with_load, io, range) end |
#download_file(output_file) ⇒ Object
285 286 287 288 289 |
# File 'lib/files.com/models/file.rb', line 285 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.
689 690 691 |
# File 'lib/files.com/models/file.rb', line 689 def download_uri @attributes[:download_uri] end |
#download_uri=(value) ⇒ Object
693 694 695 |
# File 'lib/files.com/models/file.rb', line 693 def download_uri=(value) @attributes[:download_uri] = value end |
#download_uri_with_load ⇒ Object
277 278 279 280 281 282 283 |
# File 'lib/files.com/models/file.rb', line 277 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
295 296 297 |
# File 'lib/files.com/models/file.rb', line 295 def each(*args, &block) read_io.each *args, &block end |
#each_byte(*args, &block) ⇒ Object
299 300 301 |
# File 'lib/files.com/models/file.rb', line 299 def each_byte(*args, &block) read_io.each_byte *args, &block end |
#each_char(*args, &block) ⇒ Object
303 304 305 |
# File 'lib/files.com/models/file.rb', line 303 def each_char(*args, &block) read_io.each_char *args, &block end |
#each_codepoint(*args, &block) ⇒ Object
307 308 309 |
# File 'lib/files.com/models/file.rb', line 307 def each_codepoint(*args, &block) read_io.each_codepoint *args, &block end |
#each_line(*args, &block) ⇒ Object
311 312 313 |
# File 'lib/files.com/models/file.rb', line 311 def each_line(*args, &block) each(*args, &block) end |
#empty? ⇒ Boolean
315 316 317 |
# File 'lib/files.com/models/file.rb', line 315 def empty? size == 0 end |
#eof ⇒ Object
319 320 321 |
# File 'lib/files.com/models/file.rb', line 319 def eof eof? end |
#eof? ⇒ Boolean
323 324 325 |
# File 'lib/files.com/models/file.rb', line 323 def eof? @write_io.eof? end |
#external_encoding(*args) ⇒ Object
327 328 329 |
# File 'lib/files.com/models/file.rb', line 327 def external_encoding(*args) internal_encoding *args end |
#fcntl(*_args) ⇒ Object
331 332 333 |
# File 'lib/files.com/models/file.rb', line 331 def fcntl(*_args) raise NotImplementedError end |
#fdatasync(*_args) ⇒ Object
335 336 337 |
# File 'lib/files.com/models/file.rb', line 335 def fdatasync(*_args) flush end |
#fileno(*_args) ⇒ Object
339 340 341 |
# File 'lib/files.com/models/file.rb', line 339 def fileno(*_args) id end |
#flock(*_args) ⇒ Object
343 344 345 |
# File 'lib/files.com/models/file.rb', line 343 def flock(*_args) raise NotImplementedError end |
#flush(*_args) ⇒ Object
347 348 349 350 351 352 353 354 355 356 |
# File 'lib/files.com/models/file.rb', line 347 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
358 359 360 |
# File 'lib/files.com/models/file.rb', line 358 def fsync(*args) flush *args end |
#getbyte(*args) ⇒ Object
362 363 364 |
# File 'lib/files.com/models/file.rb', line 362 def getbyte(*args) read_io.getbyte *args end |
#getc(*args) ⇒ Object
366 367 368 |
# File 'lib/files.com/models/file.rb', line 366 def getc(*args) read_io.getc *args end |
#gets(*args) ⇒ Object
370 371 372 |
# File 'lib/files.com/models/file.rb', line 370 def gets(*args) read_io.gets *args end |
#internal_encoding(*_args) ⇒ Object
386 387 388 |
# File 'lib/files.com/models/file.rb', line 386 def internal_encoding(*_args) "".encoding end |
#ioctl(*_args) ⇒ Object
390 391 392 |
# File 'lib/files.com/models/file.rb', line 390 def ioctl(*_args) raise NotImplementedError end |
#is_locked ⇒ Object
boolean - Is this folder locked and unable to be modified?
680 681 682 |
# File 'lib/files.com/models/file.rb', line 680 def is_locked @attributes[:is_locked] end |
#is_locked=(value) ⇒ Object
684 685 686 |
# File 'lib/files.com/models/file.rb', line 684 def is_locked=(value) @attributes[:is_locked] = value end |
#isatty(*_args) ⇒ Object
394 395 396 |
# File 'lib/files.com/models/file.rb', line 394 def isatty(*_args) false end |
#length ⇒ Object
int64 - Length of file.
734 735 736 |
# File 'lib/files.com/models/file.rb', line 734 def length @attributes[:length] end |
#length=(value) ⇒ Object
738 739 740 |
# File 'lib/files.com/models/file.rb', line 738 def length=(value) @attributes[:length] = value end |
#lines(*args, &block) ⇒ Object
404 405 406 |
# File 'lib/files.com/models/file.rb', line 404 def lines(*args, &block) each_line *args, &block end |
#lstat(*_args) ⇒ Object
408 409 410 |
# File 'lib/files.com/models/file.rb', line 408 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.
635 636 637 |
# File 'lib/files.com/models/file.rb', line 635 def md5 @attributes[:md5] end |
#md5=(value) ⇒ Object
639 640 641 |
# File 'lib/files.com/models/file.rb', line 639 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.
644 645 646 |
# File 'lib/files.com/models/file.rb', line 644 def mime_type @attributes[:mime_type] end |
#mime_type=(value) ⇒ Object
648 649 650 |
# File 'lib/files.com/models/file.rb', line 648 def mime_type=(value) @attributes[:mime_type] = value end |
#mkdir_parents ⇒ Object
boolean - Create parent directories if they do not exist?
743 744 745 |
# File 'lib/files.com/models/file.rb', line 743 def mkdir_parents @attributes[:mkdir_parents] end |
#mkdir_parents=(value) ⇒ Object
747 748 749 |
# File 'lib/files.com/models/file.rb', line 747 def mkdir_parents=(value) @attributes[:mkdir_parents] = value end |
#move(params = {}) ⇒ Object
Move file/folder
Parameters:
destination (required) - string - Move destination path.
876 877 878 879 880 881 882 883 884 885 886 |
# File 'lib/files.com/models/file.rb', line 876 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.
608 609 610 |
# File 'lib/files.com/models/file.rb', line 608 def mtime @attributes[:mtime] end |
#mtime=(value) ⇒ Object
612 613 614 |
# File 'lib/files.com/models/file.rb', line 612 def mtime=(value) @attributes[:mtime] = value end |
#mv(destination) ⇒ Object
412 413 414 |
# File 'lib/files.com/models/file.rb', line 412 def mv(destination) File.move(path, destination) end |
#part ⇒ Object
int64 - Part if uploading a part.
752 753 754 |
# File 'lib/files.com/models/file.rb', line 752 def part @attributes[:part] end |
#part=(value) ⇒ Object
756 757 758 |
# File 'lib/files.com/models/file.rb', line 756 def part=(value) @attributes[:part] = value end |
#parts ⇒ Object
int64 - How many parts to fetch?
761 762 763 |
# File 'lib/files.com/models/file.rb', line 761 def parts @attributes[:parts] end |
#parts=(value) ⇒ Object
765 766 767 |
# File 'lib/files.com/models/file.rb', line 765 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.
567 568 569 |
# File 'lib/files.com/models/file.rb', line 567 def path @attributes[:path] end |
#path=(value) ⇒ Object
571 572 573 |
# File 'lib/files.com/models/file.rb', line 571 def path=(value) @attributes[:path] = value end |
#permissions ⇒ Object
string - A short string representing the current user’s permissions. Can be ‘r`,`w`,`d`, `l` or any combination
662 663 664 |
# File 'lib/files.com/models/file.rb', line 662 def @attributes[:permissions] end |
#permissions=(value) ⇒ Object
666 667 668 |
# File 'lib/files.com/models/file.rb', line 666 def (value) @attributes[:permissions] = value end |
#pid(*_args) ⇒ Object
416 417 418 |
# File 'lib/files.com/models/file.rb', line 416 def pid(*_args) Process.pid end |
#pread(*args) ⇒ Object
424 425 426 |
# File 'lib/files.com/models/file.rb', line 424 def pread(*args) read_io.pread *args end |
#preview ⇒ Object
Preview - File preview
716 717 718 |
# File 'lib/files.com/models/file.rb', line 716 def preview @attributes[:preview] end |
#preview=(value) ⇒ Object
720 721 722 |
# File 'lib/files.com/models/file.rb', line 720 def preview=(value) @attributes[:preview] = value end |
#preview_id ⇒ Object
int64 - File preview ID
707 708 709 |
# File 'lib/files.com/models/file.rb', line 707 def preview_id @attributes[:preview_id] end |
#preview_id=(value) ⇒ Object
711 712 713 |
# File 'lib/files.com/models/file.rb', line 711 def preview_id=(value) @attributes[:preview_id] = value end |
#print(*args) ⇒ Object
428 429 430 |
# File 'lib/files.com/models/file.rb', line 428 def print(*args) @write_io.print *args end |
#printf(*args) ⇒ Object
432 433 434 |
# File 'lib/files.com/models/file.rb', line 432 def printf(*args) @write_io.printf *args end |
#priority_color ⇒ Object
string - Bookmark/priority color of file/folder
698 699 700 |
# File 'lib/files.com/models/file.rb', line 698 def priority_color @attributes[:priority_color] end |
#priority_color=(value) ⇒ Object
702 703 704 |
# File 'lib/files.com/models/file.rb', line 702 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.
617 618 619 |
# File 'lib/files.com/models/file.rb', line 617 def provided_mtime @attributes[:provided_mtime] end |
#provided_mtime=(value) ⇒ Object
621 622 623 |
# File 'lib/files.com/models/file.rb', line 621 def provided_mtime=(value) @attributes[:provided_mtime] = value end |
#putc(*args) ⇒ Object
436 437 438 |
# File 'lib/files.com/models/file.rb', line 436 def putc(*args) @write_io.putc *args end |
#puts(*args) ⇒ Object
440 441 442 |
# File 'lib/files.com/models/file.rb', line 440 def puts(*args) @write_io.puts *args end |
#pwrite(*args) ⇒ Object
444 445 446 |
# File 'lib/files.com/models/file.rb', line 444 def pwrite(*args) @write_io.pwrite *args end |
#read(*args) ⇒ Object
448 449 450 |
# File 'lib/files.com/models/file.rb', line 448 def read(*args) read_io.read *args end |
#read_io(**options) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/files.com/models/file.rb', line 374 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
452 453 454 |
# File 'lib/files.com/models/file.rb', line 452 def read_nonblock(*args) read_io.read_nonblock *args end |
#readbyte(*args) ⇒ Object
456 457 458 |
# File 'lib/files.com/models/file.rb', line 456 def readbyte(*args) read_io.readbyte *args end |
#readchar(*args) ⇒ Object
460 461 462 |
# File 'lib/files.com/models/file.rb', line 460 def readchar(*args) read_io.readchar *args end |
#readline(*args) ⇒ Object
464 465 466 |
# File 'lib/files.com/models/file.rb', line 464 def readline(*args) read_io.readline *args end |
#readlines(*args) ⇒ Object
468 469 470 |
# File 'lib/files.com/models/file.rb', line 468 def readlines(*args) io.readlines(*args) end |
#readpartial(*args) ⇒ Object
472 473 474 |
# File 'lib/files.com/models/file.rb', line 472 def readpartial(*args) read_io.readpartial *args end |
#ref ⇒ Object
string -
770 771 772 |
# File 'lib/files.com/models/file.rb', line 770 def ref @attributes[:ref] end |
#ref=(value) ⇒ Object
774 775 776 |
# File 'lib/files.com/models/file.rb', line 774 def ref=(value) @attributes[:ref] = value end |
#region ⇒ Object
string - Region location
653 654 655 |
# File 'lib/files.com/models/file.rb', line 653 def region @attributes[:region] end |
#region=(value) ⇒ Object
657 658 659 |
# File 'lib/files.com/models/file.rb', line 657 def region=(value) @attributes[:region] = value end |
#rename(destination) ⇒ Object
476 477 478 |
# File 'lib/files.com/models/file.rb', line 476 def rename(destination) File.rename(path, destination) end |
#reopen(*_args) ⇒ Object
480 481 482 |
# File 'lib/files.com/models/file.rb', line 480 def reopen(*_args) raise NotImplementedError end |
#restart ⇒ Object
int64 - File byte offset to restart from.
779 780 781 |
# File 'lib/files.com/models/file.rb', line 779 def restart @attributes[:restart] end |
#restart=(value) ⇒ Object
783 784 785 |
# File 'lib/files.com/models/file.rb', line 783 def restart=(value) @attributes[:restart] = value end |
#rewind ⇒ Object
484 485 486 |
# File 'lib/files.com/models/file.rb', line 484 def rewind @pos = 0 end |
#save ⇒ Object
913 914 915 916 |
# File 'lib/files.com/models/file.rb', line 913 def save new_obj = File.create(path, @attributes, @options) @attributes = new_obj.attributes end |
#seek(pos) ⇒ Object
488 489 490 |
# File 'lib/files.com/models/file.rb', line 488 def seek(pos) @pos = pos end |
#set_encoding(*_args) ⇒ Object
492 493 494 |
# File 'lib/files.com/models/file.rb', line 492 def set_encoding(*_args) raise NotImplementedError end |
#size ⇒ Object
int64 - File/Folder size
594 595 596 |
# File 'lib/files.com/models/file.rb', line 594 def size @attributes[:size] end |
#size=(value) ⇒ Object
598 599 600 |
# File 'lib/files.com/models/file.rb', line 598 def size=(value) @attributes[:size] = value end |
#stat(*_args) ⇒ Object
496 497 498 |
# File 'lib/files.com/models/file.rb', line 496 def stat(*_args) stats end |
#structure ⇒ Object
string - If copying folder, copy just the structure?
788 789 790 |
# File 'lib/files.com/models/file.rb', line 788 def structure @attributes[:structure] end |
#structure=(value) ⇒ Object
792 793 794 |
# File 'lib/files.com/models/file.rb', line 792 def structure=(value) @attributes[:structure] = value end |
#subfolders_locked=(value) ⇒ Object
675 676 677 |
# File 'lib/files.com/models/file.rb', line 675 def subfolders_locked=(value) @attributes[:subfolders_locked?] = value end |
#subfolders_locked? ⇒ Boolean
boolean - Are subfolders locked and unable to be modified?
671 672 673 |
# File 'lib/files.com/models/file.rb', line 671 def subfolders_locked? @attributes[:subfolders_locked?] end |
#sysread(*args) ⇒ Object
504 505 506 |
# File 'lib/files.com/models/file.rb', line 504 def sysread(*args) read *args end |
#sysseek(*args) ⇒ Object
508 509 510 |
# File 'lib/files.com/models/file.rb', line 508 def sysseek(*args) seek *args end |
#syswrite(*_args) ⇒ Object
512 513 514 |
# File 'lib/files.com/models/file.rb', line 512 def syswrite(*_args) raise NotImplementedError end |
#tell ⇒ Object
516 517 518 |
# File 'lib/files.com/models/file.rb', line 516 def tell pos end |
#to_i(*_args) ⇒ Object
520 521 522 |
# File 'lib/files.com/models/file.rb', line 520 def to_i(*_args) fileno end |
#to_io(*_args) ⇒ Object
524 525 526 |
# File 'lib/files.com/models/file.rb', line 524 def to_io(*_args) @write_io end |
#to_path(*_args) ⇒ Object
528 529 530 |
# File 'lib/files.com/models/file.rb', line 528 def to_path(*_args) path end |
#truncate(*_args) ⇒ Object
532 533 534 |
# File 'lib/files.com/models/file.rb', line 532 def truncate(*_args) raise NotImplementedError end |
#tty?(*_args) ⇒ Boolean
536 537 538 |
# File 'lib/files.com/models/file.rb', line 536 def tty?(*_args) false end |
#type ⇒ Object
string - Type: ‘directory` or `file`.
585 586 587 |
# File 'lib/files.com/models/file.rb', line 585 def type @attributes[:type] end |
#type=(value) ⇒ Object
589 590 591 |
# File 'lib/files.com/models/file.rb', line 589 def type=(value) @attributes[:type] = value end |
#ungetbyte(*_args) ⇒ Object
540 541 542 |
# File 'lib/files.com/models/file.rb', line 540 def ungetbyte(*_args) raise NotImplementedError end |
#ungetc(*_args) ⇒ Object
544 545 546 |
# File 'lib/files.com/models/file.rb', line 544 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.
827 828 829 830 831 832 833 834 835 836 837 |
# File 'lib/files.com/models/file.rb', line 827 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
548 549 550 |
# File 'lib/files.com/models/file.rb', line 548 def upload_file(local_file) File.upload_file(local_file.path, params: @attributes) end |
#with_rename ⇒ Object
boolean - Allow file rename instead of overwrite?
797 798 799 |
# File 'lib/files.com/models/file.rb', line 797 def with_rename @attributes[:with_rename] end |
#with_rename=(value) ⇒ Object
801 802 803 |
# File 'lib/files.com/models/file.rb', line 801 def with_rename=(value) @attributes[:with_rename] = value end |
#write(*args) ⇒ Object
552 553 554 555 556 557 558 559 560 |
# File 'lib/files.com/models/file.rb', line 552 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
562 563 564 |
# File 'lib/files.com/models/file.rb', line 562 def write_nonblock(*args) @write_io.write_nonblock *args end |