golia 1.2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/golia.gemspec +1 -1
- data/lib/golia.rb +13 -8
- metadata +3 -2
data/golia.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.description = "Golia is an website performance analyzer. Check speed and dead links."
|
9
9
|
s.default_executable = "golia"
|
10
10
|
s.executables = ["golia"]
|
11
|
-
s.version = "1.2"
|
11
|
+
s.version = "1.2.1"
|
12
12
|
s.date = Time.now.strftime("%Y-%m-%d")
|
13
13
|
s.extra_rdoc_files = Dir["*.rdoc"]
|
14
14
|
s.files = %w(README.rdoc Rakefile golia.gemspec) + Dir["lib/**/*"]
|
data/lib/golia.rb
CHANGED
@@ -7,12 +7,11 @@ require 'tmpdir'
|
|
7
7
|
class Golia
|
8
8
|
def initialize(link)
|
9
9
|
@host = begin
|
10
|
-
link = "http://#{link}" unless link =~ /^http/
|
11
|
-
"http://" + URI.parse(link).host
|
12
|
-
rescue
|
13
|
-
puts "<= Invalid url #{link}"
|
10
|
+
link = "http://#{link}" unless link =~ /^http(s?)/
|
11
|
+
"http#{$1}://" + URI.parse(link).host
|
14
12
|
end
|
15
|
-
|
13
|
+
|
14
|
+
@pid = "#{Dir.tmpdir}/golia-#{@host.gsub(/^https?:\/\//, '')}"
|
16
15
|
@checked, @links, @invalid, @valid, @long, @ms = [], [], [], [], [], []
|
17
16
|
|
18
17
|
if File.exist?(@pid)
|
@@ -20,9 +19,14 @@ class Golia
|
|
20
19
|
Process.kill(9, File.read(@pid).to_i) rescue nil
|
21
20
|
end
|
22
21
|
|
23
|
-
trap("INT") { puts "<= Golia has ended his set (crowd applauds)"; kill
|
22
|
+
trap("INT") { puts "<= Golia has ended his set (crowd applauds)"; kill }
|
24
23
|
|
25
|
-
|
24
|
+
begin
|
25
|
+
parse!(link)
|
26
|
+
rescue
|
27
|
+
puts "<= Invalid url #{link}"
|
28
|
+
kill
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
def parse!(url)
|
@@ -31,12 +35,13 @@ class Golia
|
|
31
35
|
@ms << Time.now-begun_at
|
32
36
|
body = response.read
|
33
37
|
links = body.scan(/<a.+?href=["'](.+?)["']/m).flatten
|
34
|
-
links.reject! { |link| link =~ /^\/$|^
|
38
|
+
links.reject! { |link| link =~ /^\/$|^https?|^mailto|^javascript|#/ || File.extname(link) != "" }
|
35
39
|
links.map! { |link| link = "/"+link if link !~ /^\//; @host+link }
|
36
40
|
@links.concat(links-@checked)
|
37
41
|
end
|
38
42
|
|
39
43
|
def kill
|
44
|
+
Process.kill(9, Process.pid)
|
40
45
|
FileUtils.rm_rf(@pid)
|
41
46
|
end
|
42
47
|
|