Sha256: 5b1305a11630c86c82ef9d4a0ce97c849e031f1f8adaba3e5aab6cdb4e843e53

Contents?: true

Size: 1.83 KB

Versions: 26

Compression:

Stored size: 1.83 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, '-sender', 'org.travis-ci.Travis-CI'
        end

        def available?
          System.mac? and System.os_version.to_s >= '10.8' and System.running? "NotificationCenter"
        end
      end

      class Growl
        def notify(title, body)
          system 'growlnotify', '-n', 'Travis', '--image', ICON, '-m', body, title
        end

        def available?
          System.has? 'growlnotify' and System.running? "Growl"
        end
      end

      class LibNotify
        def notify(title, body)
          system 'notify-send', '--expire-time=10000', '-i', ICON, title, CGI.escapeHTML(body)
        end

        def available?
          System.has? 'notify-send'
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
travis-1.6.9.travis.463.6 lib/travis/tools/notification.rb
travis-1.6.9.travis.462.6 lib/travis/tools/notification.rb
travis-1.6.9.travis.461.6 lib/travis/tools/notification.rb
travis-1.6.9.travis.458.6 lib/travis/tools/notification.rb
travis-1.6.8 lib/travis/tools/notification.rb
travis-1.6.8.travis.457.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.456.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.455.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.454.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.453.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.452.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.451.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.450.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.449.6 lib/travis/tools/notification.rb
travis-1.6.8.travis.447.6 lib/travis/tools/notification.rb
travis-1.6.7.travis.446.6 lib/travis/tools/notification.rb
travis-1.6.7 lib/travis/tools/notification.rb
travis-1.6.7.travis.445.6 lib/travis/tools/notification.rb
travis-1.6.7.travis.443.6 lib/travis/tools/notification.rb
travis-1.6.7.travis.442.6 lib/travis/tools/notification.rb