Sha256: 5252dd4f9e83f911cf406b813b9f86b62a19bd928e4224dbc906993ab57c8cbc
Contents?: true
Size: 1.89 KB
Versions: 13
Compression:
Stored size: 1.89 KB
Contents
require "travis" require "travis/tools/system" require "travis/tools/assets" require "cgi" module Travis module Tools module Notification extend self DEFAULT = [:osx, :growl, :libnotify] ICON = Assets['notifications/icon.png'] def new(*list) list.concat(DEFAULT) if list.empty? notification = list.map { |n| get(n) }.detect { |n| n.available? } raise ArgumentError, "no notification system found (looked for #{list.join(", ")})" unless notification notification end def get(name) const = constants.detect { |c| c.to_s[/[^:]+$/].downcase == name.to_s } raise ArgumentError, "unknown notifications type %p" % name unless const const_get(const).new end class Dummy BIN_PATH = Assets['Travis CI.app/Contents/MacOS/Travis CI'] def notify(title, body) end def available? true end end class OSX BIN_PATH = Assets["notifications/Travis CI.app/Contents/MacOS/Travis CI"] def notify(title, body) system BIN_PATH, '-message', body.to_s, '-title', title.to_s end def available? System.mac? and `sw_vers -productVersion`.strip >= '10.8' end end class Growl def initialize @command = "growlnotify" end def notify(title, body) system @command, '-n', 'Travis', '--image', ICON, '-m', body, title end def available? system "which #{@command} >/dev/null 2>/dev/null" unless System.windows? end end class LibNotify < Growl def initialize @command = "notify-send" @expire_time = 10_000 end def notify(title, body) system @command, "--expire-time=#{@expire_time}", "-i", ICON, title, CGI.escapeHTML(body) end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems