Class: YardJunk::Janitor::Resolver

Inherits:
Object
  • Object
show all
Includes:
YARD::Templates::Helpers::HtmlHelper, YARD::Templates::Helpers::MarkupHelper
Defined in:
lib/yard-junk/janitor/resolver.rb

Constant Summary collapse

OBJECT_MESSAGE_PATTERN =

This one is copied from real YARD output

"In file `%{file}':%{line}: " \
'Cannot resolve link to %{name} from text: %{link}'
FILE_MESSAGE_PATTERN =

…while this one is totally invented, YARD doesn’t check file existance at all

"In file `%{file}':%{line}: File '%{name}' does not exist: %{link}"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, yard_options) ⇒ Resolver

Returns a new instance of Resolver.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yard-junk/janitor/resolver.rb', line 21

def initialize(object, yard_options)
  @options = yard_options
  case object
  when YARD::CodeObjects::ExtraFileObject
    init_file(object)
  when YARD::Docstring
    init_docstring(object)
  else
    fail "Unknown object to resolve #{object.class}"
  end
end

Class Method Details

.resolve_all(yard_options) ⇒ Object



16
17
18
19
# File 'lib/yard-junk/janitor/resolver.rb', line 16

def self.resolve_all(yard_options)
  YARD::Registry.all.map(&:base_docstring).each { |ds| new(ds, yard_options).resolve }
  yard_options.files.each { |file| new(file, yard_options).resolve }
end

Instance Method Details

#resolveObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/yard-junk/janitor/resolver.rb', line 33

def resolve
  markup_meth = "html_markup_#{markup}"
  return unless respond_to?(markup_meth)

  send(markup_meth, @string)
    .gsub(%r{<(code|tt|pre)[^>]*>(.*?)</\1>}im, '')
    .scan(/{[^}]+}/).flatten
    .map(&CGI.method(:unescapeHTML))
    .each(&method(:try_resolve))
end