-
Notifications
You must be signed in to change notification settings - Fork 4
/
watchr.rb
33 lines (28 loc) · 1.1 KB
/
watchr.rb
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
watch('(.*).php') { |m| code_changed(m[0]) }
def code_changed(file)
run "phpunit"
end
def run(cmd)
result = `cd Test && #{cmd}`
growl result rescue nil
end
def growl(message)
puts(message)
message = message.split("\n").last(3);
osn = Config::CONFIG["target_os"].downcase
growlnotify = `which growlnotify`.chomp if osn.include?("darwin")
growlnotify = `which notify-send`.chomp if osn.include?("linux")
title = message.find { |e| /FAILURES/ =~ e } ? "FAILURES" : "PASS"
if title == "FAILURES"
image = ".watchr_images/failed.png"
tag = "<span background=\"darkred\">"
info = /\x1b\[37;41m\x1b\[2K(.*)/.match(message[1])[1]
else
image = ".watchr_images/passed.png"
tag = "<span background=\"darkgreen\">"
info = /\x1b\[30;42m\x1b\[2K(.*)/.match(message[1])[1]
end
options = "-w -n Watchr --image '#{File.expand_path(image)}' --html '#{title}' -m '#{info}'" if osn.include?("darwin")
options = "-i '#{File.expand_path(image)}' '#{title}' '#{tag}#{info}</span>'" if osn.include?("linux")
system %(#{growlnotify} #{options} &)
end