class Aptly::Snapshot

Aptly snapshots representation. @see www.aptly.info/doc/api/snapshots/

Public Class Methods

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

Create a snapshot from package refs @param name [String] name of new snapshot @return [Snapshot] representation of new snapshot

# File lib/aptly/snapshot.rb, line 70
def create(name, connection = Connection.new, **kwords)
  kwords = kwords.merge(Name: name)
  response = connection.send(:post, '/snapshots',
                             body: JSON.generate(kwords))
  new(connection, JSON.parse(response.body))
end
get(name, connection = Connection.new) click to toggle source

Get a snapshot by name @param [String] name of snapshot to get @return [Snapshot] representation of snapshot if snapshot was found

# File lib/aptly/snapshot.rb, line 80
def get(name, connection = Connection.new)
  response = connection.send(:get, "/snapshots/#{name}")
  new(connection, JSON.parse(response.body))
end
list(connection = Connection.new, **kwords) click to toggle source

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

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

Public Instance Methods

delete(**kwords) click to toggle source

Delete's this snapshot

# File lib/aptly/snapshot.rb, line 25
def delete(**kwords)
  connection.send(:delete, "/snapshots/#{self.Name}",
                  query: kwords)
end
diff(other_snapshot) click to toggle source

Find differences between this and another snapshot @param other_snapshot [Snapshot] to diff against @return [Array<Hash>] diff between the two snashots

# File lib/aptly/snapshot.rb, line 33
def diff(other_snapshot)
  endpoint = "/snapshots/#{self.Name}/diff/#{other_snapshot.Name}"
  response = @connection.send(:get, endpoint)
  JSON.parse(response.body)
end
packages(**kwords) click to toggle source

Search for a package in this snapshot @return [Array<String>] list of packages found

# File lib/aptly/snapshot.rb, line 41
def packages(**kwords)
  response = connection.send(:get, "/snapshots/#{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 snapshot 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/snapshot.rb, line 54
def publish(prefix, **kwords)
  Aptly.publish([{ Name: self.Name }], prefix, 'snapshot', kwords)
end
update!(**kwords) click to toggle source

Updates this snapshot @return [self] if the instance data was mutated @return [nil] if the instance data was not mutated

# File lib/aptly/snapshot.rb, line 13
def update!(**kwords)
  kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
  response = @connection.send(:put,
                              "/snapshots/#{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