Class: Aptly::Snapshot
- Inherits:
-
Representation
- Object
- OpenStruct
- Representation
- Aptly::Snapshot
- Includes:
- Publishable
- Defined in:
- lib/aptly/snapshot.rb
Overview
Aptly snapshots representation.
Instance Attribute Summary
Attributes inherited from Representation
Class Method Summary collapse
-
.create(name, connection = Connection.new, **kwords) ⇒ Snapshot
Create a snapshot from package refs.
-
.get(name, connection = Connection.new) ⇒ Snapshot
Get a snapshot by name.
-
.list(connection = Connection.new, **kwords) ⇒ Array<Snapshot>
List all known snapshots.
Instance Method Summary collapse
-
#delete(**kwords) ⇒ Object
Delete’s this snapshot.
-
#diff(other_snapshot) ⇒ Array<Hash>
Find differences between this and another snapshot.
-
#packages(**kwords) ⇒ Array<String>
Search for a package in this snapshot.
-
#publish(prefix, **kwords) ⇒ PublishedRepository
Convenience wrapper around publish, publishing this snapshot locally and as only source of prefix.
-
#update!(**kwords) ⇒ self?
Updates this snapshot.
Methods included from Publishable
Methods inherited from Representation
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
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
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.
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
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
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.
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
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 |