Class: BitClust::LinkChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/bitclust/link_checker.rb

Defined Under Namespace

Classes: Finding

Constant Summary collapse

EXTERNAL_TYPES =

bracket_link が扱う型のうち、DB 外を指すので検証対象外のもの

%w[url man rfc RFC ruby-list ruby-dev ruby-ext
ruby-talk ruby-core feature bug misc].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, function_database: nil) ⇒ LinkChecker

Returns a new instance of LinkChecker.



29
30
31
32
33
34
35
# File 'lib/bitclust/link_checker.rb', line 29

def initialize(db, function_database: nil)
  @db = db
  @fdb = function_database
  @findings = [] #: Array[Finding]
  @current_location = nil #: String?
  @skipped_function_refs = 0
end

Instance Attribute Details

#current_locationObject

Returns the value of attribute current_location.



39
40
41
# File 'lib/bitclust/link_checker.rb', line 39

def current_location
  @current_location
end

#findingsObject (readonly)

Returns the value of attribute findings.



37
38
39
# File 'lib/bitclust/link_checker.rb', line 37

def findings
  @findings
end

#skipped_function_refsObject (readonly)

Returns the value of attribute skipped_function_refs.



38
39
40
# File 'lib/bitclust/link_checker.rb', line 38

def skipped_function_refs
  @skipped_function_refs
end

Instance Method Details

#broken_countObject



41
42
43
# File 'lib/bitclust/link_checker.rb', line 41

def broken_count
  @findings.size
end

#check_allObject

DB 中の全ソース(ライブラリ・クラス・メソッド・doc ページ)を コンパイルして findings を収集する



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bitclust/link_checker.rb', line 47

def check_all
  @db.libraries.sort_by(&:id).each do |lib|
    check_source(lib.source_location || "library #{lib.name}") {|c| c.compile(lib.source.to_s) }
  end
  @db.classes.sort_by(&:id).each do |klass|
    check_source(klass.source_location || "class #{klass.name}") {|c| c.compile(klass.source.to_s) }
    klass.entries.sort_by(&:id).each do |m|
      check_source(m.source_location || "#{klass.name} #{m.name}") {|c| c.compile_method(m) }
    end
  end
  @db.docs.sort_by(&:id).each do |doc|
    check_source(doc.source_location || "doc #{doc.name}") {|c| c.compile(doc.source.to_s) }
  end
  @findings
end

#note_ref(type, arg) ⇒ Object

RDCompiler#bracket_link から呼ばれるフック。描画には影響しない



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/bitclust/link_checker.rb', line 64

def note_ref(type, arg)
  case type
  when 'c'   then check_class(arg)
  when 'm'   then check_method(arg)
  when 'lib' then check_library(arg)
  when 'd'   then check_doc(arg)
  when 'f'   then check_function(arg)
  when 'ref' then check_ref(arg)
  else
    unless EXTERNAL_TYPES.include?(type)
      # 未知の型は bracket_link がリテラル [[...]] のまま出力する。
      # ほぼ確実に型名の書き間違いなので報告する
      record(type, arg, 'unknown link type')
    end
  end
  nil
end