Class: Aptly::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/aptly/files.rb

Overview

Aptly files management.

Class Method Summary collapse

Class Method Details

.delete(path, connection = Connection.new, **kwords) ⇒ nil

Delete files from remote's upload directory.

Parameters:

  • path (String)

    path to delete (this may be a directory or a file)

Returns:

  • (nil)

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.

Examples:

Can be used to push into multiple repositories with one upload

Files.tmp_upload(files) do |d|
  repos.each { |r| r.add_files(d, noRemove: 1) }
end

Parameters:

  • files (Array<String>)

    paths to files to upload

  • connection (Connection) (defaults to: Connection.new)

    connection to use

Yields:

  • (String)

    the remote directory name the files were uploaded to

Returns:

  • return value of block

Since:

  • 0.9.0


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

Parameters:

  • files (Array<String>)

    paths to files to upload

  • directory (String)

    name of the directory to upload to.

  • connection (Connection) (defaults to: Connection.new)

    connection to use

Returns:

  • (Array<String>)

    list of files now on the 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