class YardJunk::Janitor::Resolver
Constants
- FILE_MESSAGE_PATTERN
…while this one is totally invented, YARD doesn't check file existance at all
- OBJECT_MESSAGE_PATTERN
This one is copied from real YARD output
Attributes
file[R]
line[R]
markup[R]
options[R]
Public Class Methods
new(object, yard_options)
click to toggle source
# 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
resolve_all(yard_options)
click to toggle source
# 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
Public Instance Methods
resolve()
click to toggle source
# 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
Private Instance Methods
init_docstring(docstring)
click to toggle source
# File lib/yard-junk/janitor/resolver.rb, line 53 def init_docstring(docstring) @string = docstring @root_object = docstring.object @file = @root_object.file @line = @root_object.line @markup = options.markup end
init_file(file)
click to toggle source
# File lib/yard-junk/janitor/resolver.rb, line 46 def init_file(file) @string = file.contents @file = file.filename @line = 1 @markup = markup_for_file(file.contents, file.filename) end
object()
click to toggle source
Used by HtmlHelper for RDoc
# File lib/yard-junk/janitor/resolver.rb, line 97 def object @string.object if @string.is_a?(YARD::Docstring) end
resolve_code_object(name, link)
click to toggle source
# File lib/yard-junk/janitor/resolver.rb, line 87 def resolve_code_object(name, link) resolved = YARD::Registry.resolve(@root_object, name, true, true) return unless resolved.is_a?(YARD::CodeObjects::Proxy) Logger.instance.register( OBJECT_MESSAGE_PATTERN % {file: file, line: line, name: name, link: link} ) end
resolve_file(name, link)
click to toggle source
# File lib/yard-junk/janitor/resolver.rb, line 79 def resolve_file(name, link) return if options.files.any? { |f| f.name == name || f.filename == name } Logger.instance.register( FILE_MESSAGE_PATTERN % {file: file, line: line, name: name, link: link} ) end
serializer()
click to toggle source
Used by HtmlHelper
# File lib/yard-junk/janitor/resolver.rb, line 102 def serializer nil end
try_resolve(link)
click to toggle source
# File lib/yard-junk/janitor/resolver.rb, line 63 def try_resolve(link) name, _comment = link.tr('{}', '').split(/\s+/, 2) # See YARD::Templates::Helpers::BaseHelper#linkify for the source of patterns # TODO: there is also {include:}, {include:file:} and {render:} syntaxes, but I've never seen # a project using them. /shrug case name when %r{://}, /^mailto:/ # that's pattern YARD uses # do nothing, assume it is correct when /^file:(\S+?)(?:#(\S+))?$/ resolve_file(Regexp.last_match[1], link) else resolve_code_object(name, link) end end