class Deadlink::Scanner
Public Class Methods
new(target_path)
click to toggle source
# File lib/deadlink/scanner.rb, line 3 def initialize(target_path) if target_path.nil? @repo_root = repo_root(".") @target_path = @repo_root else @target_path = target_path @repo_root = repo_root(@target_path) end end
Public Instance Methods
md_files()
click to toggle source
# File lib/deadlink/scanner.rb, line 21 def md_files files = [] if File.directory?(@target_path) glob do |file_path| files.push(MdFile.new(file_path, @repo_root)) end else files.push(MdFile.new(@target_path, @repo_root)) end MdFiles.new(files) end
paths(files)
click to toggle source
# File lib/deadlink/scanner.rb, line 33 def paths(files) Paths.new(files) end
valid?()
click to toggle source
# File lib/deadlink/scanner.rb, line 13 def valid? unless FileTest.exist?(@target_path) puts @target_path + ": No such file or directory" return false end true end
Private Instance Methods
git_repo?(dir)
click to toggle source
# File lib/deadlink/scanner.rb, line 54 def git_repo?(dir) Dir.exist?(File.join(dir, ".git")) end
glob() { |file_path| ... }
click to toggle source
# File lib/deadlink/scanner.rb, line 39 def glob Dir.glob(File.join(@target_path, '/**/*.{md,markdown}')) do |file_path| yield file_path end end
prev_dir(dir)
click to toggle source
# File lib/deadlink/scanner.rb, line 58 def prev_dir(dir) return "" if dir == "/" File.expand_path("../", dir) end
repo_root(target_path)
click to toggle source
# File lib/deadlink/scanner.rb, line 45 def repo_root(target_path) dir = target_path until dir.empty? do return dir if git_repo?(dir) dir = prev_dir(dir) end dir end