class Aptly::Repository

Aptly repository representation. @see www.aptly.info/doc/api/repos/

Public Class Methods

create(name, connection = Connection.new, **kwords) click to toggle source

Creates a new {Repository} @param name [String] name fo the repository @param connection [Connection] connection to use for the instance @return {Repository} newly created instance

# File lib/aptly/repository.rb, line 152
def create(name, connection = Connection.new, **kwords)
  options = kwords.merge(name: name)
  options = options.map { |k, v| [k.to_s.capitalize, v] }.to_h
  response = connection.send(:post, '/repos',
                             body: JSON.generate(options))
  new(connection, JSON.parse(response.body))
end
exist?(name, connection = Connection.new, **kwords) click to toggle source

Check if a repository exists. @param name [String] the name of the repository which might exist @param connection [Connection] connection to use for the instance @return [Boolean] whether or not the repository exists

# File lib/aptly/repository.rb, line 164
def exist?(name, connection = Connection.new, **kwords)
  get(name, connection, **kwords)
  true
rescue Aptly::Errors::NotFoundError
  false
end
get(name, connection = Connection.new, **kwords) click to toggle source

Get a {Repository} instance if the repository already exists. @param name [String] name of the repository @param connection [Connection] connection to use for the instance @return {Repository} instance if it exists

# File lib/aptly/repository.rb, line 141
def get(name, connection = Connection.new, **kwords)
  kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
  response = connection.send(:get, "/repos/#{name}",
                             query: kwords)
  new(connection, JSON.parse(response.body))
end
list(connection = Connection.new, **kwords) click to toggle source

List all known repositories. @param connection [Connection] connection to use for the instance @return [Array<Repository>] all known repositories

# File lib/aptly/repository.rb, line 174
def list(connection = Connection.new, **kwords)
  response = connection.send(:get, '/repos', query: kwords)
  JSON.parse(response.body).collect { |r| new(connection, r) }
end

Public Instance Methods

add_file(path, **kwords) click to toggle source

Add a previously uploaded file to the Repository. @return [Hash] report data as specified in the API. FIXME: this should be called file

# File lib/aptly/repository.rb, line 43
def add_file(path, **kwords)
  # Don't mangle query, the file API is inconsistently using camelCase
  # rather than CamelCase.
  response = connection.send(:post, "/repos/#{self.Name}/file/#{path}",
                             query: kwords,
                             query_mangle: false)
  hash = JSON.parse(response.body)
  error = Errors::RepositoryFileError.from_hash(hash)
  raise error if error
  hash['Report']['Added']
end
add_package(packages, **kwords) click to toggle source

Add a package (by key) to the repository. @param packages [Array<String>, String] a list of package keys or

a single package key to add to the repository. The package key(s)
must already be in the aptly database.
# File lib/aptly/repository.rb, line 76
def add_package(packages, **kwords)
  connection.send(:post, "/repos/#{self.Name}/packages",
                  query: kwords,
                  body: JSON.generate(PackageRefs: [*packages]))
  self
end
Also aliased as: add_packages
add_packages(packages, **kwords)
Alias for: add_package
delete(**kwords)

TODO: 1.0 drop delete, it's dangerous as it might as well delete packages

Alias for: delete!
delete!(**kwords) click to toggle source

Delete this repository. @return [nil] always returns nil

# File lib/aptly/repository.rb, line 33
def delete!(**kwords)
  connection.send(:delete, "/repos/#{self.Name}", query: kwords)
  nil
end
Also aliased as: delete
delete_package(packages, **kwords) click to toggle source

Deletes a package (by key) from the repository. @param packages [Array<String>, String] a list of package keys or

a single package key to add to the repository. The package key(s)
must already be in the aptly database.
# File lib/aptly/repository.rb, line 88
def delete_package(packages, **kwords)
  connection.send(:delete, "/repos/#{self.Name}/packages",
                  query: kwords,
                  body: JSON.generate(PackageRefs: [*packages]))
  self
end
Also aliased as: delete_packages
delete_packages(packages, **kwords)
Alias for: delete_package
edit!(**kwords) click to toggle source

Edit this repository's attributes as per the parameters. @note this possibly mutates the attributes depending on the HTTP response @return [self] if the instance data was mutated @return [nil] if the instance data was not mutated

# File lib/aptly/repository.rb, line 110
def edit!(**kwords)
  response = connection.send(:put,
                             "/repos/#{self.Name}",
                             body: JSON.generate(kwords))
  hash = JSON.parse(response.body, symbolize_names: true)
  return nil if hash == marshal_dump
  marshal_load(hash)
  self
end
packages(**kwords) click to toggle source

List all packages in the repository @return [Array<String>] list of packages in the repository

# File lib/aptly/repository.rb, line 65
def packages(**kwords)
  response = connection.send(:get, "/repos/#{self.Name}/packages",
                             query: kwords,
                             query_mangle: false)
  JSON.parse(response.body)
end
publish(prefix, **kwords) click to toggle source

Convenience wrapper around {Aptly.publish}, publishing this repository locally and as only source of prefix. @param prefix [String] prefix to publish under (i.e. published repo name).

This must be escaped (see {Aptly.escape_prefix})

@see Aptly.escape_prefix @return [PublishedRepository] newly published repository

# File lib/aptly/repository.rb, line 102
def publish(prefix, **kwords)
  Aptly.publish([{ Name: self.Name }], prefix, 'local', kwords)
end
snapshot(name = nil, **kwords) click to toggle source

Creates a new {Snapshot} @param name [String] name of snapshot @return {Snapshot} newly created instance

# File lib/aptly/repository.rb, line 123
def snapshot(name = nil, **kwords)
  # TODO: 1.0
  if name.nil? && !kwords.key?(:Name)
    # backwards compatible handling allows name to be passed though
    # kwords or the argument. Argument is preferred.
    raise ArgumentError, 'wrong number of arguments (given 0, expected 1)'
  end
  kwords[:Name] = name unless name.nil?
  response = connection.send(:post, "/repos/#{self.Name}/snapshots",
                             body: JSON.generate(kwords))
  Aptly::Snapshot.new(::Aptly::Connection.new, JSON.parse(response.body))
end
upload(files) click to toggle source

FIXME: needs to support single files Convenience wrapper around {Files.upload}, {#add_file} and {Files.delete}

# File lib/aptly/repository.rb, line 57
def upload(files)
  Files.tmp_upload(files, connection) do |dir|
    add_file(dir)
  end
end