deadlink 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +8 -4
- data/deadlink.gemspec +1 -0
- data/exe/deadlink +2 -2
- data/lib/deadlink/path.rb +3 -10
- data/lib/deadlink/scanner.rb +29 -2
- data/lib/deadlink/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96e8b8e7addc2ee385e95fbd7f08b1aedee81abb
|
4
|
+
data.tar.gz: 9341059baaaf395db53bd8d2f2676835cf721fe2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6abb1ca6bfb2b232946956bfcd9f3c02da7a183911ec790307610c2487ef1213aec16732289cc33feb352f7b9bcbaf0e50fa8b681897d80d03b96f0eea2ff4d4
|
7
|
+
data.tar.gz: ddb87ccf752d575f4d5416f759e3728cdc2c38d7a7ac567b9920852c15f040d840f269ecb02a60b85f396e574c04300ac7ffc3c8dcaf278f76557d6b606b957c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -20,8 +20,7 @@ case of this repository
|
|
20
20
|
|
21
21
|
```
|
22
22
|
$ git clone git@github.com:yutakakinjyo/deadlink.git
|
23
|
-
$
|
24
|
-
$ deadlink
|
23
|
+
$ deadlink deadlink/
|
25
24
|
```
|
26
25
|
|
27
26
|
result is this
|
@@ -57,12 +56,17 @@ specify path of directory
|
|
57
56
|
$ deadlink <dir>
|
58
57
|
```
|
59
58
|
|
60
|
-
if
|
59
|
+
if you want to start scanning from current directory, you can specify `.` to `<dir>` path
|
61
60
|
|
62
61
|
```
|
63
|
-
$ deadlink
|
62
|
+
$ deadlink .
|
64
63
|
```
|
65
64
|
|
65
|
+
if you not specify `<dir>` path, deadlink scan top directory of current git repository.
|
66
|
+
|
67
|
+
```
|
68
|
+
$ deadlink
|
69
|
+
```
|
66
70
|
|
67
71
|
## Development
|
68
72
|
|
data/deadlink.gemspec
CHANGED
data/exe/deadlink
CHANGED
data/lib/deadlink/path.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Deadlink
|
2
2
|
class Path
|
3
|
-
def initialize(file_path, link, index)
|
3
|
+
def initialize(file_path, link, index, repo_root)
|
4
4
|
@file_path = file_path
|
5
5
|
@link = link
|
6
6
|
@index = index
|
7
|
+
@repo_root = repo_root
|
7
8
|
end
|
8
9
|
|
9
10
|
def deadlink
|
@@ -32,20 +33,12 @@ module Deadlink
|
|
32
33
|
# split path ; <filename>#<title>
|
33
34
|
cap = @link.match(/(?<filelink>[^#]*)#*(?<anchor>.*)/)
|
34
35
|
if cap[:filelink][0] == "/"
|
35
|
-
return File.join(repo_root, cap[:filelink])
|
36
|
+
return File.join(@repo_root, cap[:filelink])
|
36
37
|
end
|
37
38
|
|
38
39
|
File.expand_path(cap[:filelink], File.dirname(@file_path))
|
39
40
|
end
|
40
41
|
|
41
|
-
def repo_root
|
42
|
-
dir = File.dirname(@file_path)
|
43
|
-
while(!dir.empty?) do
|
44
|
-
return dir if Dir.exist?(File.join(dir, ".git"))
|
45
|
-
dir = File.expand_path("../", dir)
|
46
|
-
end
|
47
|
-
dir
|
48
|
-
end
|
49
42
|
|
50
43
|
end
|
51
44
|
end
|
data/lib/deadlink/scanner.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
module Deadlink
|
2
2
|
class Scanner
|
3
3
|
def initialize(target_dir)
|
4
|
-
|
4
|
+
if target_dir.nil?
|
5
|
+
@repo_root = repo_root(".")
|
6
|
+
@target_dir = @repo_root
|
7
|
+
else
|
8
|
+
@target_dir = target_dir
|
9
|
+
@repo_root = repo_root(@target_dir)
|
10
|
+
end
|
5
11
|
end
|
6
12
|
|
7
13
|
def md_files
|
@@ -14,12 +20,33 @@ module Deadlink
|
|
14
20
|
File.open(file) do |f|
|
15
21
|
f.each_with_index do |line, index|
|
16
22
|
line.scan /\[[^\]]*\]\(([^)]+)\)/ do |link|
|
17
|
-
paths.push Path.new(f.path, link[0], index + 1)
|
23
|
+
paths.push Path.new(f.path, link[0], index + 1, @repo_root)
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
Paths.new(paths)
|
23
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def repo_root(target_dir)
|
34
|
+
dir = target_dir
|
35
|
+
until dir.empty? do
|
36
|
+
return dir if git_repo?(dir)
|
37
|
+
dir = prev_dir(dir)
|
38
|
+
end
|
39
|
+
dir
|
40
|
+
end
|
41
|
+
|
42
|
+
def git_repo?(dir)
|
43
|
+
Dir.exist?(File.join(dir, ".git"))
|
44
|
+
end
|
45
|
+
|
46
|
+
def prev_dir(dir)
|
47
|
+
return "" if dir == "/"
|
48
|
+
File.expand_path("../", dir)
|
49
|
+
end
|
50
|
+
|
24
51
|
end
|
25
52
|
end
|
data/lib/deadlink/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fakefs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: check deadlink from markdown file in your git repository
|
56
70
|
email:
|
57
71
|
- yutakakinjyo@gmail.com
|