Class: Jazzy::DocIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/jazzy/doc_index.rb

Overview

This class stores an index of symbol names for doing name lookup when resolving custom categories and autolinks.

Defined Under Namespace

Classes: LookupName, Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(all_decls) ⇒ DocIndex

Returns a new instance of DocIndex.



82
83
84
# File 'lib/jazzy/doc_index.rb', line 82

def initialize(all_decls)
  @root_scope = Scope.new_root(all_decls.group_by(&:module_name))
end

Instance Attribute Details

#root_scopeObject (readonly)

Returns the value of attribute root_scope.



80
81
82
# File 'lib/jazzy/doc_index.rb', line 80

def root_scope
  @root_scope
end

Instance Method Details

#lookup(name, context = nil) ⇒ Object

Look up a name and return the matching SourceDeclaration or nil.

‘context` is an optional SourceDeclaration indicating where the text was found, affects name resolution - see `lookup_context()` below.



90
91
92
93
94
95
96
97
# File 'lib/jazzy/doc_index.rb', line 90

def lookup(name, context = nil)
  lookup_name = LookupName.new(name)

  return lookup_fully_qualified(lookup_name) if lookup_name.fully_qualified?
  return lookup_guess(lookup_name) if context.nil?

  lookup_context(lookup_name, context)
end

#lookup_regex(regex) ⇒ Object

Look up a regex and return all matching top level SourceDeclaration.



100
101
102
# File 'lib/jazzy/doc_index.rb', line 100

def lookup_regex(regex)
  root_scope.children.map { |_, scope| scope.lookup_regex(regex) }.flatten
end