Class: OpenBuildServiceAPI::Package
- Inherits:
-
Object
- Object
- OpenBuildServiceAPI::Package
- Defined in:
- lib/models/package.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
- #binaries ⇒ Object
- #delete!(message = nil) ⇒ Object
- #description ⇒ Object
- #description=(value) ⇒ Object
- #dirty? ⇒ Boolean
-
#initialize(params = {}) ⇒ Package
constructor
A new instance of Package.
- #inspect ⇒ Object
- #meta(opts = {}) ⇒ Object
- #rebuild!(repository = nil, arch = nil) ⇒ Object
- #rebuild_failed! ⇒ Object
- #reload! ⇒ Object
- #run_service! ⇒ Object
- #save! ⇒ Object
- #sources ⇒ Object
- #title ⇒ Object
- #title=(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Package
Returns a new instance of Package.
6 7 8 9 10 |
# File 'lib/models/package.rb', line 6 def initialize(params = {}) @name = params[:name] @project = params[:project] @connection = params[:connection] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/models/package.rb', line 3 def name @name end |
#project ⇒ Object
Returns the value of attribute project.
4 5 6 |
# File 'lib/models/package.rb', line 4 def project @project end |
Instance Method Details
#binaries ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/models/package.rb', line 87 def binaries collection_data = [] @project.repositories.each do |repository| binary_data = { repository: repository, binaries: [] } repository.architectures.each do |arch| begin response = @connection.send_request(:get, "/build/#{CGI.escape(@project.name)}/#{CGI.escape(repository.to_s)}/#{CGI.escape(arch)}/#{CGI.escape(@name)}") response_xml = Nokogiri::XML(response.body) response_xml.xpath('//binarylist/binary').each do |binary| file_name = binary.attr('filename') file_size = binary.attr('size') created_at = binary.attr('mtime').to_i if BinaryHelper.binary_file?(file_name) binary_data[:binaries] << Binary.new( name: file_name, size: file_size, architecture: arch, created_at: created_at, repository: repository, package: self, connection: @connection ) end end rescue RequestError => err # in case the repository does no longer exist, we can ignore it. there are no binaries anyways next if err.error_code == '404' && err.error_summary =~ /has no repository/ # raise any other error raise end end collection_data << binary_data unless binary_data[:binaries].empty? end BinariesCollection.new(data: collection_data, connection: @connection, package: self) end |
#delete!(message = nil) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/models/package.rb', line 172 def delete!(=nil) begin @connection.send_request(:delete, "/source/#{CGI.escape(@project.name)}/#{CGI.escape(@name)}", comment: ) rescue RequestError => err raise PackageDeletionPermissionError.new("No permission to delete package '#{@name}' in project " \ "'#{@project.name}'.") if err.error_code == 'delete_package_no_permission' raise end true end |
#description ⇒ Object
28 29 30 31 32 33 |
# File 'lib/models/package.rb', line 28 def description return @description_updated if @description_updated description = .xpath('//package/description') description.empty? ? nil : description[0].text end |
#description=(value) ⇒ Object
35 36 37 38 |
# File 'lib/models/package.rb', line 35 def description=(value) @dirty = true @description_updated = value end |
#dirty? ⇒ Boolean
144 145 146 |
# File 'lib/models/package.rb', line 144 def dirty? !!@dirty end |
#inspect ⇒ Object
130 131 132 |
# File 'lib/models/package.rb', line 130 def inspect "#<#{self.class.name}:#{"0x00%x" % (object_id << 1)} @name=\"#{@name}\", @project=\"#{@project.name}\">" end |
#meta(opts = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/models/package.rb', line 54 def (opts = {}) if !@cached_meta || @meta_reload @cached_meta = @connection.send_request(:get, "/source/#{CGI.escape(@project.name)}/#{CGI.escape(@name)}/_meta").body @meta_reload = false end if opts[:no_parse] @cached_meta else Nokogiri::XML(@cached_meta) end end |
#rebuild!(repository = nil, arch = nil) ⇒ Object
134 135 136 137 |
# File 'lib/models/package.rb', line 134 def rebuild!(repository=nil, arch=nil) @connection.send_request(:post, "/build/#{CGI.escape(@project.name)}", cmd: :rebuild, package: @name, repository: repository, arch: arch) true end |
#rebuild_failed! ⇒ Object
139 140 141 142 |
# File 'lib/models/package.rb', line 139 def rebuild_failed! @connection.send_request(:post, "/build/#{CGI.escape(@project.name)}", cmd: :rebuild, package: @name, code: :failed) true end |
#reload! ⇒ Object
184 185 186 187 |
# File 'lib/models/package.rb', line 184 def reload! @meta_reload = true @sources_reload = true end |
#run_service! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/models/package.rb', line 40 def run_service! begin @connection.send_request(:post, "/source/#{CGI.escape(@project.name)}/#{CGI.escape(@name)}", cmd: :runservice) rescue RequestError => err if err.error_code == 'not_found' && err.error_summary =~ /no source service defined/ raise NoSourceServiceDefinedError.new("Package '#{@name}' in project '#{@project.name}' has no source service defined.") end raise end true end |
#save! ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/models/package.rb', line 148 def save! return false unless @dirty @meta_reload = true = .xpath('//package/title')[0].content = @title_updated if @title_updated .xpath('//package/description')[0].content = @description_updated if @description_updated # update meta definition @connection.send_request(:put, "/source/#{CGI.escape(@project.name)}/#{CGI.escape(@name)}/_meta", request_body: .to_xml) # reset updated values @dirty = false @title_updated = nil @description_updated = nil # updated cached meta @cached_meta = .to_xml true end |
#sources ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/models/package.rb', line 67 def sources return @cached_sources if @cached_sources && !@sources_reload collection_data = [] response_xml = Nokogiri::XML(@connection.send_request(:get, "/source/#{CGI.escape(@project.name)}/#{CGI.escape(@name)}").body) response_xml.xpath('//entry').each do |file| collection_data << Source.new( name: file.attr('name'), md5_hash: file.attr('md5'), size: file.attr('size'), updated_at: file.attr('mtime').to_i, package: self, connection: @connection ) end @sources_reload = false @cached_sources = SourcesCollection.new(data: collection_data, package: self, connection: @connection) end |
#title ⇒ Object
16 17 18 19 20 21 |
# File 'lib/models/package.rb', line 16 def title return @title_updated if @title_updated title = .xpath('//package/title') title.empty? ? nil : title[0].text end |
#title=(value) ⇒ Object
23 24 25 26 |
# File 'lib/models/package.rb', line 23 def title=(value) @dirty = true @title_updated = value end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/models/package.rb', line 12 def to_s @name end |