Class: DamageControl::Publisher::Growl

Inherits:
Base
  • Object
show all
Defined in:
lib/damagecontrol/publisher/growl.rb

Constant Summary collapse

NOTIFICATION_TYPES =
["Build Successful", "Build Failed"]

Instance Attribute Summary collapse

Attributes inherited from Base

#enabled

Instance Method Summary collapse

Methods inherited from Base

classes, register

Constructor Details

#initializeGrowl

Returns a new instance of Growl.



14
15
16
# File 'lib/damagecontrol/publisher/growl.rb', line 14

def initialize
  @hosts = "localhost"
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



12
13
14
# File 'lib/damagecontrol/publisher/growl.rb', line 12

def hosts
  @hosts
end

Instance Method Details

#nameObject



18
19
20
# File 'lib/damagecontrol/publisher/growl.rb', line 18

def name
  "Growl"
end

#publish(build) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/damagecontrol/publisher/growl.rb', line 22

def publish(build)
  message = nil
  index = nil
  if(build.successful?)
    message = "#{build.status_message} build (by #{build.changeset.developer})"
    index = 0
  else
    message = "#{build.changeset.developer} broke the build"
    index = 1
  end
  @hosts.split(%r{,\s*}).each do |host|
    begin
      g = ::Growl.new(host, "DamageControl (#{build.project.name})", NOTIFICATION_TYPES)
      # A bug in Ruby-Growl (or Growl) prevents the message from being sticky.
      g.notify(NOTIFICATION_TYPES[index], build.project.name, message, 0, true)
    rescue Exception => e
      Log.info("Growl publisher failed to notify #{host}: #{e.message}")
    end
  end
end