Class: Aptly::Files
- Inherits:
-
Object
- Object
- Aptly::Files
- Defined in:
- lib/aptly/files.rb
Overview
Aptly files management.
Class Method Summary collapse
-
.delete(path, connection = Connection.new, **kwords) ⇒ nil
Delete files from remote’s upload directory.
-
.tmp_upload(files, connection = Connection.new, **kwords) {|String| ... } ⇒ Object
Upload files into a temporary directory on remote.
-
.upload(files, directory, connection = Connection.new, **kwords) ⇒ Array<String>
Upload files to remote.
Class Method Details
.delete(path, connection = Connection.new, **kwords) ⇒ nil
Delete files from remote’s upload directory.
67 68 69 70 |
# File 'lib/aptly/files.rb', line 67 def delete(path, connection = Connection.new, **kwords) connection.send(:delete, "/files/#{path}", kwords) nil end |
.tmp_upload(files, connection = Connection.new, **kwords) {|String| ... } ⇒ Object
Upload files into a temporary directory on remote. This method expects a block which will be yielded to with the directory name on the remote. The directory will be deleted when this method returns. You’ll generally want to use this instead of #upload so you don’t have to worry about name collission and clean up.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/aptly/files.rb', line 50 def tmp_upload(files, connection = Connection.new, **kwords) # TODO: 1.0 find out if #upload even has a use case and maybe replace it dir = tmp_dir_name upload(files, dir, connection, **kwords) uploaded = true yield dir ensure # We have an uploaded var here as exceptions raised by upload would # still run this, but they may not have the remote file, so our # delete request would again cause an error making it harder to spot # the orignal problem. delete(dir) if uploaded end |
.upload(files, directory, connection = Connection.new, **kwords) ⇒ Array<String>
Upload files to remote
26 27 28 29 30 |
# File 'lib/aptly/files.rb', line 26 def upload(files, directory, connection = Connection.new, **kwords) files.each_with_index { |f, i| kwords["file_#{i}".to_sym] = f } response = connection.send(:post, "/files/#{directory}", kwords) JSON.parse(response.body) end |