Class: Aptly::Snapshot

Inherits:
Representation show all
Includes:
Publishable
Defined in:
lib/aptly/snapshot.rb

Overview

Aptly snapshots representation.

Instance Attribute Summary

Attributes inherited from Representation

#connection

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Publishable

#published?, #published_in

Methods inherited from Representation

#initialize

Constructor Details

This class inherits a constructor from Aptly::Representation

Class Method Details

.create(name, connection = Connection.new, **kwords) ⇒ Snapshot

Create a snapshot from package refs

Parameters:

  • name (String)

    name of new snapshot

Returns:

  • (Snapshot)

    representation of new snapshot


70
71
72
73
74
75
# 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) ⇒ Snapshot

Get a snapshot by name

Parameters:

  • name (String)

    of snapshot to get

Returns:

  • (Snapshot)

    representation of snapshot if snapshot was found


80
81
82
83
# 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) ⇒ Array<Snapshot>

List all known snapshots.

Parameters:

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

    connection to use for the instance

Returns:

  • (Array<Snapshot>)

    all known snapshots


62
63
64
65
# 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

Instance Method Details

#delete(**kwords) ⇒ Object

Delete's this snapshot


25
26
27
28
# File 'lib/aptly/snapshot.rb', line 25

def delete(**kwords)
  connection.send(:delete, "/snapshots/#{self.Name}",
                  query: kwords)
end

#diff(other_snapshot) ⇒ Array<Hash>

Find differences between this and another snapshot

Parameters:

  • other_snapshot (Snapshot)

    to diff against

Returns:

  • (Array<Hash>)

    diff between the two snashots


33
34
35
36
37
# 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) ⇒ Array<String>

Search for a package in this snapshot

Returns:

  • (Array<String>)

    list of packages found


41
42
43
44
45
46
# 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) ⇒ PublishedRepository

Convenience wrapper around Aptly.publish, publishing this snapshot locally and as only source of prefix.

Parameters:

  • prefix (String)

    prefix to publish under (i.e. published repo name). This must be escaped (see Aptly.escape_prefix)

Returns:

See Also:


54
55
56
# File 'lib/aptly/snapshot.rb', line 54

def publish(prefix, **kwords)
  Aptly.publish([{ Name: self.Name }], prefix, 'snapshot', kwords)
end

#update!(**kwords) ⇒ self?

Updates this snapshot

Returns:

  • (self)

    if the instance data was mutated

  • (nil)

    if the instance data was not mutated


13
14
15
16
17
18
19
20
21
22
# 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