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
152 153 154 155 156 157 158 |
# File 'lib/aptly/repository.rb', line 152 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.
164 165 166 167 168 169 |
# 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) ⇒ Repository
Get a Aptly::Repository instance if the repository already exists.
141 142 143 144 145 146 |
# 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) ⇒ Array<Repository>
List all known repositories.
174 175 176 177 |
# 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 |
Instance Method Details
#add_file(path, **kwords) ⇒ Hash
Add a previously uploaded file to the Repository. FIXME: this should be called file
43 44 45 46 47 48 49 50 51 52 53 |
# 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) ⇒ Object Also known as: add_packages
Add a package (by key) to the repository.
76 77 78 79 80 81 |
# 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 |
#delete!(**kwords) ⇒ nil Also known as: delete
Delete this repository.
33 34 35 36 |
# File 'lib/aptly/repository.rb', line 33 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.
88 89 90 91 92 93 |
# 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 |
#edit!(**kwords) ⇒ self?
this possibly mutates the attributes depending on the HTTP response
Edit this repository’s attributes as per the parameters.
110 111 112 113 114 115 116 117 118 |
# 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) ⇒ Array<String>
List all packages in the repository
65 66 67 68 69 70 |
# 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) ⇒ PublishedRepository
Convenience wrapper around Aptly.publish, publishing this repository locally and as only source of prefix.
102 103 104 |
# File 'lib/aptly/repository.rb', line 102 def publish(prefix, **kwords) Aptly.publish([{ Name: self.Name }], prefix, 'local', **kwords) end |
#snapshot(name = nil, **kwords) ⇒ Snapshot
Creates a new Snapshot
123 124 125 126 127 128 129 130 131 132 133 134 |
# 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) ⇒ Object
FIXME: needs to support single files Convenience wrapper around Files.upload, #add_file and Files.delete
57 58 59 60 61 |
# File 'lib/aptly/repository.rb', line 57 def upload(files) Files.tmp_upload(files, connection) do |dir| add_file(dir) end end |