Class: YARD::AppendixPlugin::NamespaceResolver
- Inherits:
-
Object
- Object
- YARD::AppendixPlugin::NamespaceResolver
- Includes:
- LegacyResolver
- Defined in:
- lib/yard-appendix/namespace_resolver.rb
Overview
This class is a necessary hack for locating the namespaces in which comments that are not tied to any CodeObjects were defined.
The issue has been reported as a bug in Ripper and until it is solved, this is required to work around it.
Defined Under Namespace
Modules: LegacyResolver
Instance Attribute Summary collapse
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Instance Method Summary collapse
-
#initialize ⇒ NamespaceResolver
constructor
A new instance of NamespaceResolver.
-
#namespace_for(statement, ns) ⇒ CodeObjects::NamespaceObject
Attempts to locate the enclosing namespace for the given statement.
-
#register_namespace(statement, ns) ⇒ void
Tracks the namespace the namespace-defining statement (such as class or module) was registered in.
Methods included from LegacyResolver
Constructor Details
#initialize ⇒ NamespaceResolver
Returns a new instance of NamespaceResolver.
34 35 36 37 38 |
# File 'lib/yard-appendix/namespace_resolver.rb', line 34 def initialize() @namespaces ||= {} super() end |
Instance Attribute Details
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
32 33 34 |
# File 'lib/yard-appendix/namespace_resolver.rb', line 32 def namespaces @namespaces end |
Instance Method Details
#namespace_for(statement, ns) ⇒ CodeObjects::NamespaceObject
Attempts to locate the enclosing namespace for the given statement. This is useful only for comment statements which are parsed by Ripper in a strange non-linear fashion that does not correlate with the namespace they’re defined in.
78 79 80 |
# File 'lib/yard-appendix/namespace_resolver.rb', line 78 def namespace_for(statement, ns) YARD::Registry.at(locate_enclosing_ns(statement, ns)) end |
#register_namespace(statement, ns) ⇒ void
Internally called by the AppendixHandler whenever a new namespace object is encountered.
This method returns an undefined value.
Tracks the namespace the namespace-defining statement (such as class or module) was registered in. This registry is used to map between free comment statements and the namespace they’re actually defined in.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/yard-appendix/namespace_resolver.rb', line 56 def register_namespace(statement, ns) klass_name = path_from_ast(statement, ns) # already registered? return if @namespaces[klass_name] klass_path = path_from_ast(statement, ns, true) log.debug "yard-appendix: registering path for namespace '#{klass_name}' => #{klass_path}" @namespaces[klass_name] = klass_path end |