Class: CruiseStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/cruisestatus.rb

Overview

Checks the status of one or more project builds on a cruisecontrol.rb server.

Example:

if CruiseStatus.new( 'http://my.cruise.com/projects.rss' ).pass?
  puts "Build passed!"
else
  puts "Build failed…Boo!"
end

Instance Method Summary collapse

Constructor Details

#initialize(feed_url) ⇒ CruiseStatus

feed_url

URL pointing to a cruise.rb RSS feed. Example: “my.cruise.com/projects.rss” or: “my.cruise.com/projects/myproject.rss”“



21
22
23
24
25
26
27
# File 'lib/cruisestatus.rb', line 21

def initialize( feed_url )
  project_feed = Kernel.open( feed_url ).read
  @doc = REXML::Document.new project_feed
rescue Exception => e
  @failures = [e.message]
  @doc = REXML::Document.new ""
end

Instance Method Details

#failuresObject

A list of failing builds. Empty if all builds passed.



37
38
39
40
41
42
43
# File 'lib/cruisestatus.rb', line 37

def failures
  @failures ||= REXML::XPath.match( @doc, "//item/title" ).select { |element|
    element.text =~ /failed$/
  }.map do |element|
    element.text.gsub( /(.*) build (.+) failed$/, '\1' )
  end
end

#pass?Boolean

True if all builds described by the feed are passing.

Returns:

  • (Boolean)


31
32
33
# File 'lib/cruisestatus.rb', line 31

def pass?
  failures.empty?
end