deadlink 0.1.0 → 0.2.0

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: 8934c98c596784a15c40112a43895da912885596
4
- data.tar.gz: 7bf9ffbc09c3f3f8dc588fb9ce49d27137dcbbf1
3
+ metadata.gz: 96e8b8e7addc2ee385e95fbd7f08b1aedee81abb
4
+ data.tar.gz: 9341059baaaf395db53bd8d2f2676835cf721fe2
5
5
  SHA512:
6
- metadata.gz: 7a7405ebc139388902b768248054bc8bfe3211aa00d75b712c834d04c1710eaa3f3ac5bb6dc16117c3563a69c489c402b0a387c2c5d39d4101a3764e653ba261
7
- data.tar.gz: 0752e347503050eeb59d81f282392595246c56888b0088eadfa152469c399d49214953fac7cdae7fae821532539dd70dbba50c7760248cd1c21389ec8e7311d9
6
+ metadata.gz: 6abb1ca6bfb2b232946956bfcd9f3c02da7a183911ec790307610c2487ef1213aec16732289cc33feb352f7b9bcbaf0e50fa8b681897d80d03b96f0eea2ff4d4
7
+ data.tar.gz: ddb87ccf752d575f4d5416f759e3728cdc2c38d7a7ac567b9920852c15f040d840f269ecb02a60b85f396e574c04300ac7ffc3c8dcaf278f76557d6b606b957c
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ vendor
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
- $ cd deadlink
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 your not specify <dir> path, `.` path is specfied.
59
+ if you want to start scanning from current directory, you can specify `.` to `<dir>` path
61
60
 
62
61
  ```
63
- $ deadlink => $ 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
 
@@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.10.6"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "fakefs"
25
26
 
26
27
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'deadlink'
4
4
 
5
- target_dir = ARGV[0].nil? ? '.' : ARGV[0]
6
- Deadlink.scan(target_dir)
5
+ target_dir = ARGV[0]
6
+ Deadlink.scan(target_dir)
@@ -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
@@ -1,7 +1,13 @@
1
1
  module Deadlink
2
2
  class Scanner
3
3
  def initialize(target_dir)
4
- @target_dir = target_dir
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
@@ -1,3 +1,3 @@
1
1
  module Deadlink
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
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.1.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-06 00:00:00.000000000 Z
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