Class: Aptly::Repository
- Inherits:
-
Representation
- Object
- OpenStruct
- Representation
- Aptly::Repository
- Includes:
- Publishable
- Defined in:
- lib/aptly/repository.rb
Overview
Aptly repository representation.
Instance Attribute Summary
Attributes inherited from Representation
Class Method Summary collapse
-
.create(name, connection = Connection.new, **kwords) ⇒ Repository
Creates a new Repository.
-
.exist?(name, connection = Connection.new, **kwords) ⇒ Boolean
Check if a repository exists.
-
.get(name, connection = Connection.new, **kwords) ⇒ Repository
Get a Repository instance if the repository already exists.
-
.list(connection = Connection.new, **kwords) ⇒ Array<Repository>
List all known repositories.
Instance Method Summary collapse
-
#add_file(path, **kwords) ⇒ Hash
Add a previously uploaded file to the Repository.
-
#add_package(packages, **kwords) ⇒ Object
(also: #add_packages)
Add a package (by key) to the repository.
-
#delete!(**kwords) ⇒ nil
(also: #delete)
Delete this repository.
-
#delete_package(packages, **kwords) ⇒ Object
(also: #delete_packages)
Deletes a package (by key) from the repository.
-
#edit!(**kwords) ⇒ self?
Edit this repository’s attributes as per the parameters.
-
#packages(**kwords) ⇒ Array<String>
List all packages in the repository.
-
#publish(prefix, **kwords) ⇒ PublishedRepository
Convenience wrapper around publish, publishing this repository locally and as only source of prefix.
-
#snapshot(name = nil, **kwords) ⇒ Snapshot
Creates a new Snapshot.
-
#upload(files) ⇒ Object
FIXME: needs to support single files Convenience wrapper around Files.upload, #add_file and Files.delete.
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) ⇒ Repository
Creates a new Aptly::Repository
134 135 136 137 138 139 140 |
# File 'lib/aptly/repository.rb', line 134 def create(name, connection = Connection.new, **kwords) = kwords.merge(name: name) = .map { |k, v| [k.to_s.capitalize, v] }.to_h response = connection.send(:post, '/repos', body: JSON.generate()) new(connection, JSON.parse(response.body)) end |
.exist?(name, connection = Connection.new, **kwords) ⇒ Boolean
Check if a repository exists.
146 147 148 149 150 151 |
# File 'lib/aptly/repository.rb', line 146 def exist?(name, connection = Connection.new, **kwords) get(name, connection, **kwords) true rescue Aptly::Errors::NotFoundError false end |
.get(name, connection = Connection.new, **kwords) ⇒ Repository
Get a Aptly::Repository instance if the repository already exists.
123 124 125 126 127 128 |
# File 'lib/aptly/repository.rb', line 123 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) ⇒ Array<Repository>
List all known repositories.
156 157 158 159 |
# File 'lib/aptly/repository.rb', line 156 def list(connection = Connection.new, **kwords) response = connection.send(:get, '/repos', query: kwords) JSON.parse(response.body).collect { |r| new(connection, r) } end |
Instance Method Details
#add_file(path, **kwords) ⇒ Hash
Add a previously uploaded file to the Repository. FIXME: this should be called file
27 28 29 30 31 32 33 34 |
# File 'lib/aptly/repository.rb', line 27 def add_file(path, **kwords) response = connection.send(:post, "/repos/#{self.Name}/file/#{path}", query: kwords) hash = JSON.parse(response.body) error = Errors::RepositoryFileError.from_hash(hash) raise error if error hash['Report']['Added'] end |
#add_package(packages, **kwords) ⇒ Object Also known as: add_packages
Add a package (by key) to the repository.
60 61 62 63 64 65 |
# File 'lib/aptly/repository.rb', line 60 def add_package(packages, **kwords) connection.send(:post, "/repos/#{self.Name}/packages", query: kwords, body: JSON.generate(PackageRefs: [*packages])) self end |
#delete!(**kwords) ⇒ nil Also known as: delete
Delete this repository.
17 18 19 20 |
# File 'lib/aptly/repository.rb', line 17 def delete!(**kwords) connection.send(:delete, "/repos/#{self.Name}", query: kwords) nil end |
#delete_package(packages, **kwords) ⇒ Object Also known as: delete_packages
Deletes a package (by key) from the repository.
72 73 74 75 76 77 |
# File 'lib/aptly/repository.rb', line 72 def delete_package(packages, **kwords) connection.send(:delete, "/repos/#{self.Name}/packages", query: kwords, body: JSON.generate(PackageRefs: [*packages])) self end |
#edit!(**kwords) ⇒ self?
this possibly mutates the attributes depending on the HTTP response
Edit this repository’s attributes as per the parameters.
92 93 94 95 96 97 98 99 100 |
# File 'lib/aptly/repository.rb', line 92 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) ⇒ Array<String>
List all packages in the repository
49 50 51 52 53 54 |
# File 'lib/aptly/repository.rb', line 49 def packages(**kwords) response = connection.send(:get, "/repos/#{self.Name}/packages", query: kwords, query_mangle: false) JSON.parse(response.body) end |
#publish(prefix, **kwords) ⇒ PublishedRepository
Convenience wrapper around Aptly.publish, publishing this repository locally and as only source of prefix.
84 85 86 |
# File 'lib/aptly/repository.rb', line 84 def publish(prefix, **kwords) Aptly.publish([{ Name: self.Name }], prefix, 'local', kwords) end |
#snapshot(name = nil, **kwords) ⇒ Snapshot
Creates a new Snapshot
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/aptly/repository.rb', line 105 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) ⇒ Object
FIXME: needs to support single files Convenience wrapper around Files.upload, #add_file and Files.delete
38 39 40 41 42 43 44 45 |
# File 'lib/aptly/repository.rb', line 38 def upload(files) prefix = "#{self.class.to_s.tr(':', '_')}-#{Socket.gethostname}-" directory = Dir::Tmpname.make_tmpname(prefix, nil) Files.upload(files, directory, connection) add_file(directory) ensure Files.delete(directory, connection) end |