Class: QCloudHive::Manifest
- Inherits:
-
Object
- Object
- QCloudHive::Manifest
- Defined in:
- lib/qcloudhive/manifest.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#projects ⇒ Object
Returns the value of attribute projects.
-
#remotes ⇒ Object
Returns the value of attribute remotes.
Instance Method Summary collapse
- #addModule(url, path) ⇒ Object
- #deleteModule(url) ⇒ Object
- #deleteModuleByName(name) ⇒ Object
- #existModule?(name) ⇒ Boolean
- #flushStorage ⇒ Object
-
#initialize(filePath) ⇒ Manifest
constructor
A new instance of Manifest.
- #moduleByName(name) ⇒ Object
- #remoteByName(name) ⇒ Object
- #sourceURLByModuleName(name) ⇒ Object
- #toXML ⇒ Object
Constructor Details
#initialize(filePath) ⇒ Manifest
Returns a new instance of Manifest.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/qcloudhive/manifest.rb', line 167 def initialize(filePath) @manifestPath = filePath @doc = Nokogiri::XML(File.open(filePath)) @default = ManifestDefault.new @projects = [] @doc.xpath("//project").each { |p| remote = p.attribute("remote").value name = p.attribute("name").value if name.start_with?("/") name= name[1..name.length] end path = p.attribute("path").value project = ManifestProject.new(remote, name, path) @projects << project L.debug project } @remotes = [] @doc.xpath("//remote").each { |r| name = r.attribute("name").value fetch = r.attribute("fetch").value if not fetch.end_with?("/") fetch = fetch+"/" end remote = ManifestRemote.new(name, fetch) @remotes << remote } end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
165 166 167 |
# File 'lib/qcloudhive/manifest.rb', line 165 def default @default end |
#projects ⇒ Object
Returns the value of attribute projects.
163 164 165 |
# File 'lib/qcloudhive/manifest.rb', line 163 def projects @projects end |
#remotes ⇒ Object
Returns the value of attribute remotes.
164 165 166 |
# File 'lib/qcloudhive/manifest.rb', line 164 def remotes @remotes end |
Instance Method Details
#addModule(url, path) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/qcloudhive/manifest.rb', line 196 def addModule(url, path) uri = URI(url) host = uri.host scheme = uri.scheme remote = nil uriPath = uri.path.split(".").first if uriPath.start_with?("/") uriPath= uriPath[1..uriPath.length] end name = uriPath.split("/").last @projects.each { |p| if p.name == uriPath return @projects end } @remotes.each { |r| rfetch = URI(r.fetch) if rfetch.host == host and rfetch.scheme == scheme remote = r.name end } projectPath = "#{name}" if path != nil if path.start_with?("/") path = path[1..-1] end if path.end_with?("/") projectPath = "#{path}#{name}" else if path.length > 0 projectPath = "#{path}/#{name}" else projectPath = "#{name}" end end end remote = ManifestProject.new(remote, uriPath ,projectPath) @projects << remote end |
#deleteModule(url) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/qcloudhive/manifest.rb', line 259 def deleteModule(url) uri = URI(url) uriPath = uri.path.split(".").first if uriPath.start_with?("/") uriPath= uriPath[1..uriPath.length] end L.debug "#{@projects}" @projects=@projects.select{ |e| e.name != uriPath } L.debug "#{@projects}" end |
#deleteModuleByName(name) ⇒ Object
272 273 274 275 276 277 278 |
# File 'lib/qcloudhive/manifest.rb', line 272 def deleteModuleByName(name) L.debug "#{@projects}" @projects=@projects.select{ |e| e.moduleName != name } L.debug "#{@projects}" end |
#existModule?(name) ⇒ Boolean
236 237 238 239 240 241 242 243 244 |
# File 'lib/qcloudhive/manifest.rb', line 236 def existModule?(name) @projects.select{ |p| if p.name.start_with?(Config.team) p.name == Config.team+"/#{name}" else p.name == name end }.count > 0 end |
#flushStorage ⇒ Object
307 308 309 310 311 |
# File 'lib/qcloudhive/manifest.rb', line 307 def flushStorage File.open(@manifestPath, "w") { |f| f.write toXML } end |
#moduleByName(name) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/qcloudhive/manifest.rb', line 246 def moduleByName(name) @projects.each { |p| L.info p.name } @projects.select{ |p| if p.name.start_with?(Config.team) p.name == Config.team+"/#{name}" else p.name == name end }.first end |
#remoteByName(name) ⇒ Object
312 313 314 |
# File 'lib/qcloudhive/manifest.rb', line 312 def remoteByName(name) @remotes.select { |e| e.name == name }.first end |
#sourceURLByModuleName(name) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/qcloudhive/manifest.rb', line 315 def sourceURLByModuleName(name) L.debug "#{@projects}" moduleSpec = @projects.select{ |e| e.moduleName != name }.first if moduleSpec.nil? return nil end remote = remoteByName(moduleSpec.remote) return "#{remote.fetch}#{moduleSpec.name}" end |
#toXML ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/qcloudhive/manifest.rb', line 280 def toXML doc = Nokogiri::XML('''<?xml version="1.0" encoding="UTF-8"?><manifest></manifest>''') manifest = doc.xpath("//manifest").first @remotes.each { |r| ele = Nokogiri::XML::Element.new("remote", doc) ele.set_attribute("name", r.name) ele.set_attribute("fetch", r.fetch) manifest.add_child(ele) } default = Nokogiri::XML::Element.new("default", doc) default.set_attribute("revision", @default.revision) default.set_attribute("remote", @default.remote) default.set_attribute("sync-j", @default.sync_j) manifest.add_child(default) @projects.each { |r| ele =Nokogiri::XML::Element.new("project", doc) ele.set_attribute("name",r.name) ele.set_attribute("remote" ,r.remote ) ele.set_attribute("path" ,r.path) manifest.add_child(ele) } return doc.to_s end |