Class: Aptly::Repository
- Inherits:
-
Representation
- Object
- OpenStruct
- Representation
- Aptly::Repository
- 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) ⇒ Object
Delete this repository.
-
#delete_package(packages, **kwords) ⇒ Object
(also: #delete_packages)
Deletes a package (by key) from the repository.
-
#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.
- #published? ⇒ Boolean
-
#published_in {|pub| ... } ⇒ Array<PublishedRepository>
Lists all PublishedRepositories self is published in.
-
#upload(files) ⇒ Object
FIXME: needs to support single files Convenience wrapper around Files.upload and #add_file.
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
119 120 121 122 123 124 125 |
# File 'lib/aptly/repository.rb', line 119 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.
131 132 133 134 135 136 |
# File 'lib/aptly/repository.rb', line 131 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.
108 109 110 111 112 113 |
# File 'lib/aptly/repository.rb', line 108 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.
141 142 143 144 |
# File 'lib/aptly/repository.rb', line 141 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
19 20 21 22 23 24 25 26 |
# File 'lib/aptly/repository.rb', line 19 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) fail 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.
52 53 54 55 56 57 |
# File 'lib/aptly/repository.rb', line 52 def add_package(packages, **kwords) connection.send(:post, "/repos/#{self.Name}/packages", query: kwords, body: JSON.generate(PackageRefs: [*packages])) self end |
#delete(**kwords) ⇒ Object
Delete this repository.
12 13 14 |
# File 'lib/aptly/repository.rb', line 12 def delete(**kwords) connection.send(:delete, "/repos/#{self.Name}", query: kwords) end |
#delete_package(packages, **kwords) ⇒ Object Also known as: delete_packages
Deletes a package (by key) from the repository.
64 65 66 67 68 69 |
# File 'lib/aptly/repository.rb', line 64 def delete_package(packages, **kwords) connection.send(:delete, "/repos/#{self.Name}/packages", query: kwords, body: JSON.generate(PackageRefs: [*packages])) self end |
#packages(**kwords) ⇒ Array<String>
List all packages in the repository
41 42 43 44 45 46 |
# File 'lib/aptly/repository.rb', line 41 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.
76 77 78 |
# File 'lib/aptly/repository.rb', line 76 def publish(prefix, **kwords) Aptly.publish([{ Name: self.Name }], prefix, 'local', kwords) end |
#published? ⇒ Boolean
81 82 83 |
# File 'lib/aptly/repository.rb', line 81 def published? !published_in.empty? end |
#published_in {|pub| ... } ⇒ Array<PublishedRepository>
Lists all PublishedRepositories self is published in. Namely self must be a source of the published repository in order for it to appear here. This method always returns an array of affected published repositories. If you use this method with a block it will additionally yield each published repository that would appear in the array, making it a shorthand for Array#each.
93 94 95 96 97 98 99 100 101 |
# File 'lib/aptly/repository.rb', line 93 def published_in Aptly::PublishedRepository.list(connection).select do |pub| pub.Sources.each do |src| next false unless src.Name == self.Name yield repo if block_given? true end end end |
#upload(files) ⇒ Object
FIXME: needs to support single files Convenience wrapper around Files.upload and #add_file
30 31 32 33 34 35 36 37 |
# File 'lib/aptly/repository.rb', line 30 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 # FIXME: delete dir? end |