deadlink 0.6.1 → 0.6.2

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
  SHA1:
3
- metadata.gz: f5c27052c618a63f9259c3e713ad3caca6a59a69
4
- data.tar.gz: a43ca6c875240100e25f86719e7dda5138b968bf
3
+ metadata.gz: b863c28a4eea2f7ba320860e8fc897de7a85fe67
4
+ data.tar.gz: 1855c3606b41771e512d347084294f4751f3e689
5
5
  SHA512:
6
- metadata.gz: feced0fab0a213457c77a125ec3474126710cd1166e91c27215e171a0343b669d3fe819c4b71e4e05b9e3230cfba6805022c4a3d7f26b387eb2392d0ede9f346
7
- data.tar.gz: 2f0ee19fcb8d3839f00f8257115126fa3a73e3730863eae76f412d554588ce460981327a672aae9b4dac8dd3c092060a87bbd9f6734a2581c7884066395785fc
6
+ metadata.gz: de47980c6041ca67a30f39ff24222e8bece1380050653c624b8e70f810548f6033c671e0fd73c567cd6219bc4157dbd3a473199da3484a366c7818e020056617
7
+ data.tar.gz: e7615ca3e01b28556bcde16d983afe2dc2c21c7cf86cd7f68a14b55ed341d6da073a77ffdf669f7bf29c66ed2c3e8c5cb522b5b32f7877552c57c62b8cc9754f
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
- before_install: gem install bundler -v 1.10.6
4
+ before_install: gem install bundler -v 1.11.0
5
5
  cache: bundler
6
6
  notifications:
7
7
  email: false
data/deadlink.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.10.6"
22
+ spec.add_development_dependency "bundler", "~> 1.11.0"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest"
25
25
  spec.add_development_dependency "fakefs"
@@ -7,33 +7,49 @@ module Deadlink
7
7
  @path = file_path
8
8
  @headers = []
9
9
  @link_paths = []
10
- init(repo_root)
10
+ attribute(repo_root)
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def init(repo_root)
15
+ def attribute(repo_root)
16
16
  File.open(@path) do |f|
17
+ prev_line = nil
17
18
  f.each_with_index do |line,index|
18
- attribute(line, index, repo_root)
19
+ sharp_header(line) { |header| @headers.push header }
20
+ under_line_header(line, prev_line) { |header| @headers.push header }; prev_line = line
21
+ link(line, index, repo_root) { |path| @link_paths.push path }
19
22
  end
20
23
  end
21
24
  end
22
25
 
23
- def attribute(line, index, repo_root)
24
- if line =~ heading_pattern # capture sharp header part
25
- header = Regexp.last_match[:header].downcase.rstrip.gsub(/\s+/," ")
26
- @headers.push header.gsub(" ", "-")
26
+ def sharp_header(line)
27
+ if line =~ sharp_header_pattern # capture sharp header part
28
+ header = Regexp.last_match[:header].downcase.rstrip
29
+ yield header.gsub(" ", "-")
27
30
  end
31
+ end
32
+
33
+ def under_line_header(line, prev_line)
34
+ if line =~ under_header_pattern && !prev_line.nil?
35
+ yield prev_line.chomp
36
+ end
37
+ end
38
+
39
+ def link(line, index, repo_root)
28
40
  line.scan link_pattern do |link| # capthure links path part
29
- @link_paths.push Path.new(@path, link[0], index + 1, repo_root)
41
+ yield Path.new(@path, link[0].rstrip, index + 1, repo_root)
30
42
  end
31
43
  end
32
44
 
33
- def heading_pattern
45
+ def sharp_header_pattern
34
46
  /^\#{1,6} +(?<header>.+)/
35
47
  end
36
48
 
49
+ def under_header_pattern
50
+ /^[-]+$|^[=]+$/
51
+ end
52
+
37
53
  def link_pattern
38
54
  /\[[^\]]*\]\((?<link>[^)]+)\)/
39
55
  end
@@ -11,17 +11,15 @@ module Deadlink
11
11
  @files = files
12
12
  end
13
13
 
14
- def header_include?(path, anchor)
15
- file = find_by(path)
16
- return file.headers.include?(anchor) unless file.nil?
17
- false
14
+ def find_by(path)
15
+ @files.each { |file| return file if abs(file.path) == abs(path) }
16
+ nil
18
17
  end
19
18
 
20
19
  private
21
20
 
22
- def find_by(path)
23
- @files.each { |file| return file if file.path == path }
24
- nil
21
+ def abs(path)
22
+ File.expand_path(path, File.dirname(path))
25
23
  end
26
24
 
27
25
  end
data/lib/deadlink/path.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module Deadlink
2
3
  class Path
3
4
 
@@ -10,10 +11,11 @@ module Deadlink
10
11
  @repo_root = repo_root
11
12
 
12
13
  hash = split_link(link)
13
- @link_file_path = hash[:filepath]
14
14
  @anchor = hash[:anchor]
15
+ @link_file_path = hash[:filepath]
15
16
 
16
- @abusolute_link_file_path = abusolute_link_file_path
17
+
18
+ @abs_link_file_path = abs_link_file_path
17
19
  end
18
20
 
19
21
  def deadlink?(files)
@@ -24,17 +26,23 @@ module Deadlink
24
26
 
25
27
  def anchor_invalid?(files)
26
28
  return false if @anchor.empty?
27
- if @link_file_path.empty?
28
- return !files.header_include?(@cur_file_path, @anchor)
29
- end
30
- !files.header_include?(@abusolute_link_file_path, @anchor)
29
+
30
+ # e.g [](#anchor)
31
+ path = only_anchor? ? @cur_file_path : @abs_link_file_path
32
+ file = files.find_by(path)
33
+ return !file.headers.include?(@anchor)
34
+ end
35
+
36
+ def only_anchor?
37
+ @link_file_path.empty? && !@anchor.empty?
31
38
  end
32
39
 
33
40
  def exist?
34
- FileTest.exist?(@abusolute_link_file_path)
41
+ FileTest.exist?(@abs_link_file_path)
35
42
  end
36
43
 
37
- def abusolute_link_file_path
44
+ def abs_link_file_path
45
+
38
46
  if specify_root?(@link_file_path)
39
47
  return File.join(@repo_root, @link_file_path)
40
48
  else
@@ -1,3 +1,3 @@
1
1
  module Deadlink
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deadlink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yutakakinjyo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.10.6
19
+ version: 1.11.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.10.6
26
+ version: 1.11.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement