sla 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sla.rb +0 -1
- data/lib/sla/checker.rb +11 -24
- data/lib/sla/command_line.rb +5 -5
- data/lib/sla/link.rb +51 -8
- data/lib/sla/version.rb +1 -1
- metadata +1 -2
- data/lib/sla/page.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ec41399fd977f97a9987ff148f9846f1aecae2
|
4
|
+
data.tar.gz: 93d2d55e73f5f812a5615a324af9b41031a183cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb27195220e441b517b7eac34466479117c1a4e4f195f39fe753abb1348b9270833c00278834921b80f1af92cf17cf70da51330516e339d53b28ce11d30d72a1
|
7
|
+
data.tar.gz: 465e9965dddb77655299f70d04f79694746ca81af7333052fa43f2748a3e4e397c5a9f869f5bdd6f802c278bc0662b8e37655f87c7bad58ea6e140aa3e995433
|
data/lib/sla.rb
CHANGED
data/lib/sla/checker.rb
CHANGED
@@ -2,43 +2,30 @@ module SLA
|
|
2
2
|
class Checker
|
3
3
|
include Colsole
|
4
4
|
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :max_depth, :checked_links
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@max_depth = 10
|
9
9
|
@checked_links = []
|
10
|
-
@next_check ||= []
|
11
10
|
end
|
12
11
|
|
13
12
|
def count
|
14
13
|
checked_links.count
|
15
14
|
end
|
16
15
|
|
17
|
-
def
|
18
|
-
|
16
|
+
def check(link, depth=1, &block)
|
17
|
+
link = Link.new link, depth: depth if link.is_a? String
|
18
|
+
link.validate
|
19
|
+
yield link if block_given?
|
19
20
|
|
20
|
-
|
21
|
+
return if checked_links.include? link.url
|
22
|
+
checked_links.push link.url
|
21
23
|
|
22
|
-
|
23
|
-
check_url url, depth, &block
|
24
|
-
if depth < max_depth && !next_check.empty?
|
25
|
-
on_check next_check, depth+1, &block
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def check_url(url, depth, &_block)
|
31
|
-
page = Page.new url, depth: depth
|
32
|
-
page.validate
|
33
|
-
|
34
|
-
yield page if block_given?
|
24
|
+
return unless link.valid?
|
35
25
|
return if depth >= max_depth
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
page.links.each do |link|
|
41
|
-
next_check.push link.url unless next_check.include? link.url
|
26
|
+
|
27
|
+
link.sublinks.each do |sublink|
|
28
|
+
check sublink, depth+1, &block
|
42
29
|
end
|
43
30
|
end
|
44
31
|
end
|
data/lib/sla/command_line.rb
CHANGED
@@ -40,15 +40,15 @@ module SLA
|
|
40
40
|
|
41
41
|
log = []
|
42
42
|
|
43
|
-
checker.
|
44
|
-
indent = '-' *
|
43
|
+
checker.check start_url do |link|
|
44
|
+
indent = '-' * link.depth
|
45
45
|
|
46
|
-
status =
|
46
|
+
status = link.status
|
47
47
|
colored_status = color_status status
|
48
48
|
failed +=1 if status != '200'
|
49
49
|
|
50
|
-
say "#{count} #{colored_status} #{indent} #{
|
51
|
-
log.push "#{count} #{status} #{indent} #{
|
50
|
+
say "#{count} #{colored_status} #{indent} #{link.ident}"
|
51
|
+
log.push "#{count} #{status} #{indent} #{link.ident}" unless @no_log
|
52
52
|
count += 1
|
53
53
|
end
|
54
54
|
|
data/lib/sla/link.rb
CHANGED
@@ -1,12 +1,59 @@
|
|
1
1
|
module SLA
|
2
2
|
class Link
|
3
|
-
attr_accessor :text, :href
|
3
|
+
attr_accessor :text, :href, :status, :depth, :real_uri
|
4
4
|
attr_reader :parent
|
5
5
|
|
6
6
|
def initialize(href, opts={})
|
7
|
-
@href
|
8
|
-
@text
|
9
|
-
|
7
|
+
@href = href
|
8
|
+
@text = opts[:text]
|
9
|
+
@depth = opts[:depth] || 1
|
10
|
+
self.parent = opts[:parent] || @href
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
validate
|
15
|
+
status == '200'
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate
|
19
|
+
content
|
20
|
+
end
|
21
|
+
|
22
|
+
def content
|
23
|
+
@content ||= content!
|
24
|
+
end
|
25
|
+
|
26
|
+
def content!
|
27
|
+
response = Cache.get url
|
28
|
+
self.status = response.error ? '404' : '200'
|
29
|
+
self.real_uri = response.base_uri
|
30
|
+
response.content
|
31
|
+
end
|
32
|
+
|
33
|
+
def ident
|
34
|
+
full_uri.request_uri
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
full_uri.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def doc
|
42
|
+
@doc ||= Nokogiri::HTML content
|
43
|
+
end
|
44
|
+
|
45
|
+
def sublinks
|
46
|
+
@sublinks ||= sublinks!
|
47
|
+
end
|
48
|
+
|
49
|
+
def sublinks!
|
50
|
+
anchors = doc.css('a')
|
51
|
+
result = []
|
52
|
+
anchors.each do |a|
|
53
|
+
link = Link.new a['href'], text: a.text, parent: real_uri, depth: depth+1
|
54
|
+
result.push link if link.interesting?
|
55
|
+
end
|
56
|
+
result
|
10
57
|
end
|
11
58
|
|
12
59
|
def uri
|
@@ -26,10 +73,6 @@ module SLA
|
|
26
73
|
URI.join parent, href
|
27
74
|
end
|
28
75
|
|
29
|
-
def url
|
30
|
-
full_uri.to_s
|
31
|
-
end
|
32
|
-
|
33
76
|
def external?
|
34
77
|
parent.host != full_uri.host
|
35
78
|
end
|
data/lib/sla/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
@@ -165,7 +165,6 @@ files:
|
|
165
165
|
- lib/sla/command_line.rb
|
166
166
|
- lib/sla/docopt.txt
|
167
167
|
- lib/sla/link.rb
|
168
|
-
- lib/sla/page.rb
|
169
168
|
- lib/sla/version.rb
|
170
169
|
homepage: https://github.com/DannyBen/sla
|
171
170
|
licenses:
|
data/lib/sla/page.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module SLA
|
2
|
-
class Page
|
3
|
-
attr_accessor :depth, :status, :base_uri
|
4
|
-
attr_reader :url
|
5
|
-
|
6
|
-
def initialize(url, opts={})
|
7
|
-
@url = url
|
8
|
-
@base_uri = url
|
9
|
-
@status = '000'
|
10
|
-
self.depth = opts[:depth] if opts[:depth]
|
11
|
-
end
|
12
|
-
|
13
|
-
def valid?
|
14
|
-
validate
|
15
|
-
status == '200'
|
16
|
-
end
|
17
|
-
|
18
|
-
def validate
|
19
|
-
content
|
20
|
-
end
|
21
|
-
|
22
|
-
def name
|
23
|
-
@name ||= name!
|
24
|
-
end
|
25
|
-
|
26
|
-
def name!
|
27
|
-
uri = URI.parse url
|
28
|
-
if uri.request_uri.empty? || uri.request_uri == '/'
|
29
|
-
url
|
30
|
-
else
|
31
|
-
uri.request_uri
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def content
|
36
|
-
@content ||= content!
|
37
|
-
end
|
38
|
-
|
39
|
-
def content!
|
40
|
-
response = Cache.get url
|
41
|
-
self.status = response.error ? '404' : '200'
|
42
|
-
self.base_uri = response.base_uri
|
43
|
-
response.content
|
44
|
-
end
|
45
|
-
|
46
|
-
def doc
|
47
|
-
@doc ||= Nokogiri::HTML content
|
48
|
-
end
|
49
|
-
|
50
|
-
def links
|
51
|
-
@links ||= links!
|
52
|
-
end
|
53
|
-
|
54
|
-
def links!
|
55
|
-
anchors = doc.css('a')
|
56
|
-
result = []
|
57
|
-
anchors.each do |a|
|
58
|
-
link = Link.new a['href'], text: a.text, parent: base_uri
|
59
|
-
result.push link if link.interesting?
|
60
|
-
end
|
61
|
-
result
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|