Class: OpenBuildServiceAPI::Project
- Inherits:
-
Object
- Object
- OpenBuildServiceAPI::Project
- Defined in:
- lib/models/project.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#projects ⇒ Object
Returns the value of attribute projects.
Instance Method Summary collapse
- #branch_package(source_project, source_package, package_name_after_branch = nil) ⇒ Object
- #delete!(message = nil) ⇒ Object
-
#initialize(params = {}) ⇒ Project
constructor
A new instance of Project.
- #meta(opts = {}) ⇒ Object
- #packages ⇒ Object
- #public_key ⇒ Object
- #reload! ⇒ Object
- #repositories ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Project
Returns a new instance of Project.
5 6 7 8 9 |
# File 'lib/models/project.rb', line 5 def initialize(params = {}) @name = params[:name] @projects = params[:projects] @connection = params[:connection] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/models/project.rb', line 3 def name @name end |
#projects ⇒ Object
Returns the value of attribute projects.
3 4 5 |
# File 'lib/models/project.rb', line 3 def projects @projects end |
Instance Method Details
#branch_package(source_project, source_package, package_name_after_branch = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/models/project.rb', line 76 def branch_package(source_project, source_package, package_name_after_branch=nil) params = { cmd: 'branch', target_project: name } params[:target_package] = package_name_after_branch ? package_name_after_branch : source_package begin response = @connection.send_request(:post, "/source/#{CGI.escape(source_project.to_s)}/#{CGI.escape(source_package.to_s)}", params) response_xml = Nokogiri::XML(response.body) @package_reload = true Package.new(name: response_xml.xpath('//data[@name="targetpackage"]')[0].text, connection: @connection, project: self) rescue RequestError => err raise PackageAlreadyExistsError.new("Package '#{params[:target_package]}' does already exist " \ "in project '#{@name}'.") if err.error_code == 'double_branch_package' raise TargetProjectPermissionError.new("Branching to project '#{@name}' is not possible: No " \ "access in target project.") if err.error_code == 'cmd_execution_no_permission' raise end end |
#delete!(message = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/models/project.rb', line 51 def delete!(=nil) begin @connection.send_request(:delete, "/source/#{CGI.escape(@name)}", comment: ) rescue RequestError => err raise ProjectDeletionPermissionError.new("No permission to delete project '#{@name}'.") if err.error_code == 'delete_project_no_permission' raise end true end |
#meta(opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/models/project.rb', line 15 def (opts = {}) if !@cached_meta || @meta_reload @cached_meta = @connection.send_request(:get, "/source/#{CGI.escape(@name)}/_meta").body @meta_reload = false end if opts[:no_parse] @cached_meta else Nokogiri::XML(@cached_meta) end end |
#packages ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/models/project.rb', line 62 def packages return @cached_packages if @cached_packages && !@package_reload @package_reload = false collection_data = [] packages = Nokogiri::XML(@connection.send_request(:get, "/source/#{CGI.escape(@name)}").body) packages.xpath('//entry').each do |package| collection_data << Package.new(name: package.attr('name'), connection: @connection, project: self) end @cached_packages = PackagesCollection.new(connection: @connection, project: self, data: collection_data) end |
#public_key ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/models/project.rb', line 95 def public_key @cached_public_key if @cached_public_key && !@public_key_reload @public_key_reload = false response = @connection.send_request(:get, "/source/#{CGI.escape(@name)}/_pubkey") response.body end |
#reload! ⇒ Object
103 104 105 106 107 |
# File 'lib/models/project.rb', line 103 def reload! @package_reload = true @public_key_reload = true @meta_reload = true end |
#repositories ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/models/project.rb', line 28 def repositories collection_data = [] .xpath('//repository').each do |repository| paths = [] archs = [] repository.children.each do |child| if child.is_a?(Nokogiri::XML::Element) if child.name == 'path' paths << { project: child.attr('project'), repository: child.attr('repository') } elsif child.name == 'arch' archs << child.text end end end collection_data << Repository.new(name: repository.attr('name'), paths: paths, architectures: archs, connection: @connection, project: self) end collection_data end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/models/project.rb', line 11 def to_s @name end |