deadlink 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f42e427eaed4d72f32f1792483e63ada02693bee
4
- data.tar.gz: 9bce889bdc0bf45a1c9f801e5a38fa828d32d501
3
+ metadata.gz: eb5e6436cde33615811d3788e82efa4aae463b0b
4
+ data.tar.gz: c4b3acda36bf178319b056384504370b5fa22802
5
5
  SHA512:
6
- metadata.gz: 4d390237db254c21ca8ad04326dc0984d08fa0f65fbd2d7c6b7007e375fef371d567b5b12f8ac59f242ca4ec75141462fbaae728339203523d54d784760d2ec0
7
- data.tar.gz: bad4ecfdcb120bedd548d9774bbd422ceff9430fe66f6d87595bb8a4b718840aba1af271e93ed22294d33e0df1a43c599149c1f7b1b630e7c99fa19bca89d0ed
6
+ metadata.gz: bafda7f50283eb4ecc701de7bcf60436697dc5611da533e7dcff1044fdd04804089ccb3a7b324898f5e32770c6ecaf1cd02594494b884670601ba3ddfd3c6151
7
+ data.tar.gz: a7e9dc7d73724d5af0eb690a1ec90a94b3cfadf017b4254d4f2e3fea6f26e77ae511323d0a178e46045a9f7bd36fb8170557a544fd5d4338a30fab0f62ad6a1d
data/.travis.yml CHANGED
@@ -4,5 +4,7 @@ rvm:
4
4
 
5
5
  before_install: gem install bundler -v 1.10.6
6
6
 
7
+ cache: bundler
8
+
7
9
  notifications:
8
10
  email: false
data/exe/deadlink CHANGED
@@ -3,3 +3,4 @@
3
3
  require 'deadlink'
4
4
 
5
5
  Deadlink.scan()
6
+
@@ -2,10 +2,21 @@ module Deadlink
2
2
  class Decorator
3
3
  def self.print_info(path,opts)
4
4
  if opts['p']
5
- puts '+' + path.index.to_s + " " + path.cur_file_path
5
+ for_editor(path)
6
6
  else
7
- puts path.link + ' in ' + path.cur_file_path + ' line: ' + path.index.to_s
7
+ default(path)
8
8
  end
9
9
  end
10
+
11
+ private
12
+
13
+ def self.for_editor(path)
14
+ puts '+' + path.index.to_s + " " + path.cur_file_path
15
+ end
16
+
17
+ def self.default(path)
18
+ puts path.link + ' in ' + path.cur_file_path + ' line: ' + path.index.to_s
19
+ end
20
+
10
21
  end
11
22
  end
data/lib/deadlink/path.rb CHANGED
@@ -4,10 +4,9 @@ module Deadlink
4
4
  attr_reader :link, :cur_file_path, :index
5
5
 
6
6
  def initialize(cur_file_path, link, index, repo_root)
7
- @link = link
8
7
  @cur_file_path = cur_file_path
8
+ @link = link
9
9
  @index = index
10
-
11
10
  @repo_root = repo_root
12
11
 
13
12
  hash = split_link(link)
@@ -16,14 +15,10 @@ module Deadlink
16
15
  end
17
16
 
18
17
  def deadlink?
19
- !exist? && ignore
18
+ !FileTest.exist?(abusolute_path) && ignore
20
19
  end
21
20
 
22
21
  private
23
-
24
- def exist?
25
- File.exist?(link_path) || Dir.exist?(link_path)
26
- end
27
22
 
28
23
  def ignore
29
24
  !url?
@@ -33,20 +28,20 @@ module Deadlink
33
28
  @link =~ /https?:\/\/[\S]+/
34
29
  end
35
30
 
36
- def link_path
37
- if absolute_path?(@link_file_path)
31
+ def abusolute_path
32
+ if specify_root?(@link_file_path)
38
33
  return File.join(@repo_root, @link_file_path)
34
+ else
35
+ return File.expand_path(@link_file_path, File.dirname(@cur_file_path))
39
36
  end
40
-
41
- File.expand_path(@link_file_path, File.dirname(@cur_file_path))
42
37
  end
43
38
 
44
39
  def split_link(link)
45
- # split <filenpath>#<title>
40
+ # split <filenpath>#<anchor>
46
41
  hash = link.match(/(?<filepath>[^#]*)#*(?<anchor>.*)/)
47
42
  end
48
43
 
49
- def absolute_path?(path)
44
+ def specify_root?(path)
50
45
  path[0] == "/"
51
46
  end
52
47
 
@@ -1,17 +1,30 @@
1
1
  module Deadlink
2
2
  class Scanner
3
- def initialize(target_dir)
4
- if target_dir.nil?
3
+ def initialize(target_path)
4
+ if target_path.nil?
5
5
  @repo_root = repo_root(".")
6
- @target_dir = @repo_root
6
+ @target_path = @repo_root
7
7
  else
8
- @target_dir = target_dir
9
- @repo_root = repo_root(@target_dir)
8
+ @target_path = target_path
9
+ @repo_root = repo_root(@target_path)
10
10
  end
11
11
  end
12
12
 
13
+ def valid?
14
+ unless FileTest.exist?(@target_path)
15
+ puts @target_path + ": No such file or directory"
16
+ return false
17
+ end
18
+ return true
19
+ end
20
+
13
21
  def md_files
14
- Dir.glob(File.join(@target_dir, '/**/*.md'))
22
+ if File.directory?(@target_path)
23
+ Dir.glob(File.join(@target_path, '/**/*.{md,markdown}'))
24
+ else
25
+ files = []
26
+ files.push(@target_path)
27
+ end
15
28
  end
16
29
 
17
30
  def paths(files)
@@ -30,8 +43,8 @@ module Deadlink
30
43
 
31
44
  private
32
45
 
33
- def repo_root(target_dir)
34
- dir = target_dir
46
+ def repo_root(target_path)
47
+ dir = target_path
35
48
  until dir.empty? do
36
49
  return dir if git_repo?(dir)
37
50
  dir = prev_dir(dir)
@@ -1,3 +1,3 @@
1
1
  module Deadlink
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/deadlink.rb CHANGED
@@ -9,11 +9,20 @@ module Deadlink
9
9
  def self.scan()
10
10
 
11
11
  opts = ARGV.getopts('','p')
12
- target_dir = ARGV[0]
12
+ target_path = ARGV[0]
13
13
 
14
+ scanner = Scanner.new(target_path)
15
+
16
+ unless scanner.valid?
17
+ exit 1
18
+ end
14
19
 
15
- scanner = Scanner.new(target_dir)
16
20
  files = scanner.md_files
21
+
22
+ if files.empty?
23
+ exit 0
24
+ end
25
+
17
26
  paths = scanner.paths(files)
18
27
  paths.print_deadlinks(opts)
19
28
  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.3.0
4
+ version: 0.4.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-14 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.4.8
114
+ rubygems_version: 2.5.0
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: check deadlink from markdown file in your git repository