sla 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9490644ba70e3da7f217f5293b85aaa203f57a51d01988a128be223f4334b5a4
4
- data.tar.gz: 2c4dceedf37fa8ed810453fd87711db3b3cd085261152793dd68f6275e3d6c57
3
+ metadata.gz: b7ab0a2c8232984458067a9d9a501011c50c4e6e3c500631a516b2f495b02fa6
4
+ data.tar.gz: 3d1af9be056a2cabc8dbf39dc37d14795b549f4f4e19803be82663d761eb7e5e
5
5
  SHA512:
6
- metadata.gz: 94c5c9bf6f91cefab617dfdb2bf50719fcbbeece4f6e2df1b1528ebcc647652ed25ced8f31bbfdd202dc7858bcb13e4e86ed7c0b5c9ca670b053008fdf7b761b
7
- data.tar.gz: 882b2031c63f1d33282245a3ac1258585a67f98fb95d8b7822fd0ead0c01cdc88e5eed1804a68bc3bbefd50e2a5a526afb5ae27244de806852b53cc46abfe363
6
+ metadata.gz: 10d4a3dd2bcffcba10b4866ab5200dd9ded805c73bc196666efbe827005ea10620180d61667d02e9aa28c809dba07e4ca6d6dd7f2f6fd8668d3c741d526c332f
7
+ data.tar.gz: 9998c057a56599449bb8077c1fdfba755d70a4877d83a6cbe9d25b243248d6b588d08bdc2c8cb9db87b6ecbf90852a8efde1eb31871e13ed7705d220bbc2484c
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
- Site Link Analyzer
2
- ==================================================
1
+ # Site Link Analyzer
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/sla.svg)](https://badge.fury.io/rb/sla)
5
- [![Build Status](https://travis-ci.com/DannyBen/sla.svg?branch=master)](https://travis-ci.com/DannyBen/sla)
4
+ [![Build Status](https://github.com/DannyBen/sla/workflows/Test/badge.svg)](https://github.com/DannyBen/sla/actions?query=workflow%3ATest)
6
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/f78192aead8a74535a24/maintainability)](https://codeclimate.com/github/DannyBen/sla/maintainability)
7
6
 
8
7
  ---
@@ -11,25 +10,30 @@ SLA is a simple broken links checker, with built in caching.
11
10
 
12
11
  ![SLA Demo](demo/cast.svg "SLA Demo")
13
12
 
14
- Install
15
- --------------------------------------------------
13
+ ## Install
16
14
 
17
- ```
15
+ ### Install using Ruby
16
+
17
+ ```shell
18
18
  $ gem install sla
19
19
  ```
20
20
 
21
+ ### Install using Docker
22
+
23
+ ```shell
24
+ alias sla='docker run --rm -it --network host -v /tmp/sla_cache:/app/cache dannyben/sla'
25
+ ```
26
+
27
+ The `--network host` flag is only necessary if you intend to check links on `localhost`.
21
28
 
22
- Features
23
- --------------------------------------------------
29
+ ## Features
24
30
 
25
31
  - Easy to use command line interface.
26
32
  - Built in caching, to avoid overtaxing the server.
27
33
  - Show and save list of broken links to a log file.
28
34
  - Exits with non zero code on failure, for CI integration.
29
35
 
30
-
31
- Usage
32
- --------------------------------------------------
36
+ ## Usage
33
37
 
34
38
  ```
35
39
  $ sla --help
@@ -91,3 +95,12 @@ Examples:
91
95
  sla example.com --ignore "/admin /customer/login"
92
96
 
93
97
  ```
98
+
99
+ ## Contributing / Support
100
+
101
+ If you experience any issue, have a question or a suggestion, or if you wish
102
+ to contribute, feel free to [open an issue][issues].
103
+
104
+ ---
105
+
106
+ [issues]: https://github.com/DannyBen/sla/issues
data/lib/sla/checker.rb CHANGED
@@ -9,14 +9,11 @@ module SLA
9
9
  end
10
10
 
11
11
  def check(page, &block)
12
- return if ignore? page
13
- return if page.depth >= max_depth
14
- return unless page.valid?
12
+ return if skip? page
15
13
 
16
14
  yield [:source, page] if block_given?
17
15
 
18
- pages = page.pages
19
- pages.reject! { |page| page.external? } if !check_external
16
+ pages = page_list page
20
17
 
21
18
  pages.each do |page|
22
19
  if checked.has_key? page.url or ignore? page
@@ -37,6 +34,18 @@ module SLA
37
34
 
38
35
  private
39
36
 
37
+ def page_list(page)
38
+ if check_external
39
+ page.pages
40
+ else
41
+ page.pages.reject { |page| page.external? }
42
+ end
43
+ end
44
+
45
+ def skip?(page)
46
+ ignore?(page) or page.depth >= max_depth or !page.valid?
47
+ end
48
+
40
49
  def ignore?(page)
41
50
  return false unless ignore
42
51
 
@@ -6,12 +6,11 @@ module SLA
6
6
  attr_accessor :count, :failed
7
7
 
8
8
  def initialize
9
- @count = 0
10
- @failed = 0
9
+ @count, @failed = 0, 0
11
10
  end
12
11
 
13
12
  def success?
14
- failed == 0
13
+ count > 0 and failed == 0
15
14
  end
16
15
 
17
16
  def handle(action, page)
@@ -10,9 +10,14 @@ module SLA
10
10
  @count += 1
11
11
 
12
12
  return if page.valid?
13
-
14
13
  @failed += 1
15
14
 
15
+ show_status page
16
+ end
17
+
18
+ private
19
+
20
+ def show_status(page)
16
21
  if last_source
17
22
  say "!txtpur!SOURCE #{last_source}"
18
23
  @last_source = nil
@@ -1,16 +1,25 @@
1
1
  module SLA
2
2
  module Formatters
3
3
  class TTY < Base
4
- attr_reader :last_source
4
+ attr_reader :last_source, :screen_width
5
5
 
6
6
  def handle(action, page)
7
- screen_width = terminal_width
8
-
7
+ @screen_width = terminal_width
9
8
  @last_source = page.url if action == :source
10
9
 
11
10
  return unless action == :check
12
11
  @count += 1
13
12
 
13
+ show_status page
14
+ end
15
+
16
+ def footer_prefix
17
+ terminal? ? "\033[2K\n" : "\n"
18
+ end
19
+
20
+ private
21
+
22
+ def show_status(page)
14
23
  if page.valid?
15
24
  status = "PASS"
16
25
  color = "!txtgrn!"
@@ -34,11 +43,6 @@ module SLA
34
43
  resay "[#{failed}/#{count} @ #{page.depth}] #{color}#{status}!txtrst! #{url} "
35
44
  end
36
45
 
37
- def footer_prefix
38
- terminal? ? "\033[2K\n" : "\n"
39
- end
40
-
41
-
42
46
  end
43
47
  end
44
- end
48
+ end
@@ -5,30 +5,37 @@ module SLA
5
5
  case action
6
6
  when :source
7
7
  say "\n!txtpur!SOURCE #{page.url}"
8
-
8
+
9
9
  when :check
10
- @count += 1
10
+ show_check_status page
11
11
 
12
- show_error = false
12
+ when :skip
13
+ say " !txtblu!SKIP!txtrst! #{page.depth} #{page.url}"
13
14
 
14
- if page.valid?
15
- status = "PASS"
16
- color = "!txtgrn!"
17
- else
18
- @failed += 1
19
- status = "FAIL"
20
- color = "!txtred!"
21
- show_error = page.code != 404
22
- end
15
+ end
16
+ end
23
17
 
24
- say " #{color}#{status}!txtrst! #{page.depth} #{page.url}"
25
- say " !txtred!#{page.code}!txtrst! #{page.error}" if show_error
18
+ private
26
19
 
27
- when :skip
28
- say " !txtblu!SKIP!txtrst! #{page.depth} #{page.url}"
20
+ def show_check_status(page)
21
+ @count += 1
22
+
23
+ show_error = false
29
24
 
25
+ if page.valid?
26
+ status = "PASS"
27
+ color = "!txtgrn!"
28
+ else
29
+ @failed += 1
30
+ status = "FAIL"
31
+ color = "!txtred!"
32
+ show_error = page.code != 404
30
33
  end
34
+
35
+ say " #{color}#{status}!txtrst! #{page.depth} #{page.url}"
36
+ say " !txtred!#{page.code}!txtrst! #{page.error}" if show_error
31
37
  end
38
+
32
39
  end
33
40
  end
34
41
  end
data/lib/sla/page.rb CHANGED
@@ -1,86 +1,88 @@
1
- class Page
2
- attr_reader :uri, :parent, :depth
3
-
4
- def initialize(uri, parent: nil, depth: 0)
5
- if uri.is_a? String
6
- uri = "http://#{uri}" unless uri.start_with? 'http'
7
- uri = URI.parse uri
8
- uri.fragment = false
1
+ module SLA
2
+ class Page
3
+ attr_reader :uri, :parent, :depth
4
+
5
+ def initialize(uri, parent: nil, depth: 0)
6
+ if uri.is_a? String
7
+ uri = "http://#{uri}" unless uri.start_with? 'http'
8
+ uri = URI.parse uri
9
+ uri.fragment = false
10
+ end
11
+
12
+ @uri, @parent, @depth = uri, parent, depth
9
13
  end
10
14
 
11
- @uri, @parent, @depth = uri, parent, depth
12
- end
15
+ def error
16
+ response.error
17
+ end
13
18
 
14
- def error
15
- response.error
16
- end
19
+ def code
20
+ response.code || 'ERR'
21
+ end
17
22
 
18
- def code
19
- response.code || 'ERR'
20
- end
23
+ def external?
24
+ parent ? (uri.host != parent.uri.host) : false
25
+ end
21
26
 
22
- def external?
23
- parent ? (uri.host != parent.uri.host) : false
24
- end
27
+ def inspect
28
+ "#<Page url: #{url}, depth: #{depth}>"
29
+ end
25
30
 
26
- def inspect
27
- "#<Page url: #{url}, depth: #{depth}>"
28
- end
31
+ def pages
32
+ @pages ||= pages!
33
+ end
29
34
 
30
- def pages
31
- @pages ||= pages!
32
- end
35
+ def url
36
+ uri.to_s
37
+ end
33
38
 
34
- def url
35
- uri.to_s
36
- end
39
+ def valid?
40
+ !response.error
41
+ end
37
42
 
38
- def valid?
39
- !response.error
40
- end
43
+ private
41
44
 
42
- private
45
+ def anchors
46
+ @anchors ||= dom.css('a[href]')
47
+ end
43
48
 
44
- def anchors
45
- @anchors ||= dom.css('a[href]')
46
- end
49
+ def content
50
+ @content ||= response.content
51
+ end
47
52
 
48
- def content
49
- @content ||= response.content
50
- end
53
+ def dom
54
+ @dom ||= Nokogiri::HTML content
55
+ end
51
56
 
52
- def dom
53
- @dom ||= Nokogiri::HTML content
54
- end
57
+ def normalize_url(new_url)
58
+ new_url = URI.parse new_url
59
+ new_url.fragment = false
55
60
 
56
- def normalize_url(new_url)
57
- new_url = URI.parse new_url
58
- new_url.fragment = false
61
+ result = new_url.absolute? ? new_url : URI.join(url, new_url)
59
62
 
60
- result = new_url.absolute? ? new_url : URI.join(url, new_url)
63
+ result.scheme =~ /^http/ ? result.to_s : nil
64
+ end
61
65
 
62
- result.scheme =~ /^http/ ? result.to_s : nil
63
- end
66
+ def pages!
67
+ result = {}
68
+ anchors.each do |a|
69
+ url = normalize_url a['href']
70
+ next unless url
71
+ page = Page.new url, parent: self, depth: depth+1
72
+ result[url] = page
73
+ end
74
+ result.values
75
+ end
64
76
 
65
- def pages!
66
- result = {}
67
- anchors.each do |a|
68
- url = normalize_url a['href']
69
- next unless url
70
- page = Page.new url, parent: self, depth: depth+1
71
- result[url] = page
77
+ def response
78
+ @response ||= response!
72
79
  end
73
- result.values
74
- end
75
80
 
76
- def response
77
- @response ||= response!
78
- end
81
+ def response!
82
+ response = WebCache.get url
83
+ @uri = response.base_uri
84
+ response
85
+ end
79
86
 
80
- def response!
81
- response = WebCache.get url
82
- @uri = response.base_uri
83
- response
84
87
  end
85
-
86
- end
88
+ end
data/lib/sla/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SLA
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.0.3
113
+ rubygems_version: 3.2.16
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Command Line Site Link Analyzer