Sha256: a82488e15d7a08c12fcfe29f1c741af2d128f7e9c3056c34fc6b6807fcf4c968

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

class Autotest
  class Notify
    def self.notify(state)
      title = "#{state.to_s.capitalize} -- Autotest"

      command = case RUBY_PLATFORM
      when /linux/
        title = "'#{title}'"
        case linux_lib
        when :'notify-send' then "#{linux_lib} #{title}"
        when :kdialog then "#{linux_lib} --title #{title}"
        when :zenity then "#{linux_lib} --title #{title}"
        end
      when /darwin/
        "growlnotify -n autotest -t #{title}"
      when /cygwin/
        "sncmd /m '#{title}'"
      when /mswin/
        require 'snarl'
        Snarl.show_message(title)
      end

      system command
    end

    private

    def self.linux_lib
      libs = [:'notify-send', :kdialog, :zenity]
      @@linux_lib ||= libs.detect do |l|
        system("which #{l} > /dev/null 2>&1")
      end or puts("Install one of #{libs.join(', ')} to get notified")
    end
  end
end

[:red, :green, :all_good].each do |hook|
  Autotest.add_hook hook do
    begin
      Autotest::Notify.notify(hook)
    rescue Exception => e # errors in autotest would fail silently
      puts e.to_s
      puts e.backtrace
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
autotest-standalone-4.5.1 lib/autotest/notify.rb