File: notify.rb

package info (click to toggle)
ruby-notify 0.5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: ruby: 112; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,054 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'fileutils'
require 'erb'
require 'notify/version'

module Notify
  def self.which(prog, path=ENV['PATH'])
    if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin|cygwin/
      path.split(File::PATH_SEPARATOR).each {|dir|
        f = File.join(dir,prog+".exe")
        return f if File.executable?(File.join(f)) && !File.directory?(f)
      }
      nil
    else
      return system("which #{prog} > /dev/null 2>&1")
    end
  end

  def self.html_escape(text)
    ERB::Util.html_escape(text)
  end
end

dir = File.dirname(__FILE__)
begin
  if ENV['NOTIFY']
    require File.join(dir, "notify/#{ENV['NOTIFY']}")
  else
    Dir[File.join(dir, "notify/*.rb")].each do |filename|
      break if Notify.methods.include?(:notify)
      require filename
    end
  end
rescue LoadError
  # A safeguard against bad libraries or edge-case errors.
  puts "Notify can't find the library specified."
end

module Notify
  unless methods.include?(:notify)
    def self.notify(title, message, options = {})
      puts "#{title}: #{message}"
    end
  end
end