Sha256: 303226d5843680fa829fb707d26ca8c23af3d841703d9e2f7ffd9f7a6d4aa550

Contents?: true

Size: 1.62 KB

Versions: 11

Compression:

Stored size: 1.62 KB

Contents

require "travis/tools/system"
require "terminal-notifier"
require "cgi"

module Travis
  module Tools
    module Notification
      extend self
      DEFAULT = [:osx, :growl, :libnotify]

      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
        def notify(title, body)
        end

        def available?
          true
        end
      end

      class OSX
        def notify(title, body)
          TerminalNotifier.notify(body, :title => title)
        end

        def available?
          System.mac? and TerminalNotifier.available?
        end
      end

      class Growl
        def initialize
          @command = "growlnotify"
        end

        def notify(title, body)
          system @command, '-n', 'Travis', '-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}", title, CGI.escapeHTML(body)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
travis-1.5.7.travis.345.4 lib/travis/tools/notification.rb
travis-1.5.7.travis.341.4 lib/travis/tools/notification.rb
travis-1.5.7.travis.338.4 lib/travis/tools/notification.rb
travis-1.5.6 lib/travis/tools/notification.rb
travis-1.5.6.travis.337.4 lib/travis/tools/notification.rb
travis-1.5.6.travis.336.4 lib/travis/tools/notification.rb
travis-1.5.6.travis.333.4 lib/travis/tools/notification.rb
travis-1.5.6.travis.332.4 lib/travis/tools/notification.rb
travis-1.5.6.travis.330.4 lib/travis/tools/notification.rb
travis-1.5.6.travis.329.4 lib/travis/tools/notification.rb
travis-1.5.6.travis.326.4 lib/travis/tools/notification.rb