Class: OpenBuildServiceAPI::PackagesCollection
- Inherits:
-
AbstractCollection
- Object
- AbstractCollection
- OpenBuildServiceAPI::PackagesCollection
- Defined in:
- lib/collections/packages_collection.rb
Instance Method Summary collapse
- #exists?(name) ⇒ Boolean
- #find(name) ⇒ Object
- #find!(name) ⇒ Object
-
#initialize(params = {}) ⇒ PackagesCollection
constructor
A new instance of PackagesCollection.
Methods inherited from AbstractCollection
Constructor Details
#initialize(params = {}) ⇒ PackagesCollection
Returns a new instance of PackagesCollection.
3 4 5 6 7 8 9 |
# File 'lib/collections/packages_collection.rb', line 3 def initialize(params = {}) raise ArgumentError.new('The dataset needs to be provided as an Array.') if params[:data] && !params[:data].is_a?(Array) @connection = params[:connection] @project = params[:project] @data = params[:data] ? params[:data] : [] end |
Instance Method Details
#exists?(name) ⇒ Boolean
11 12 13 |
# File 'lib/collections/packages_collection.rb', line 11 def exists?(name) !!find(name) end |
#find(name) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/collections/packages_collection.rb', line 15 def find(name) begin package_data = Nokogiri::XML(@connection.send_request(:get, "/source/#{CGI.escape(@project.name)}/#{name}").body) Package.new(name: package_data.root.attr('name'), connection: @connection, project: @project) rescue RequestError => err return if err.error_code == 'unknown_package' raise end end |
#find!(name) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/collections/packages_collection.rb', line 25 def find!(name) package = find(name) raise PackageNotFoundError.new("Package '#{name}' does not exist in project '#{@project.name}'.") unless package package end |