Class: YARD::RegistryResolver
- Inherits:
-
Object
- Object
- YARD::RegistryResolver
- Includes:
- CodeObjects::NamespaceMapper
- Defined in:
- lib/yard/registry_resolver.rb
Overview
Handles all logic for complex lexical and inherited object resolution. Used by YARD::Registry.resolve, so there is no need to use this class directly.
Instance Method Summary collapse
-
#initialize(registry = Registry) ⇒ RegistryResolver
constructor
Creates a new resolver object for a registry.
-
#lookup_by_path(path, opts = {}) ⇒ CodeObjects::Base, ...
Performs a lookup on a given path in the registry.
Methods included from CodeObjects::NamespaceMapper
#clear_separators, #default_separator, #register_separator, #separators, #separators_for_type, #separators_match, #types_for_separator
Constructor Details
#initialize(registry = Registry) ⇒ RegistryResolver
Creates a new resolver object for a registry.
15 16 17 |
# File 'lib/yard/registry_resolver.rb', line 15 def initialize(registry = Registry) @registry = Registry end |
Instance Method Details
#lookup_by_path(path, opts = {}) ⇒ CodeObjects::Base, ...
Performs a lookup on a given path in the registry. Resolution will occur in a similar way to standard Ruby identifier resolution, doing lexical lookup, as well as (optionally) through the inheritance chain. A proxy object can be returned if the lookup fails for future resolution. The proxy will be type hinted with the type
used in the original lookup.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/yard/registry_resolver.rb', line 45 def lookup_by_path(path, opts = {}) path = path.to_s namespace = opts[:namespace] inheritance = opts[:inheritance] || false proxy_fallback = opts[:proxy_fallback] || false type = opts[:type] if namespace.is_a?(CodeObjects::Proxy) return proxy_fallback ? CodeObjects::Proxy.new(namespace, path, type) : nil end if namespace == :root || !namespace namespace = @registry.root else namespace = namespace.parent until namespace.is_a?(CodeObjects::NamespaceObject) end orignamespace = namespace if path =~ /\A#{default_separator}/ path, namespace = $', @registry.root end resolved = nil while namespace && !resolved resolved = lookup_path_direct(namespace, path, type) resolved ||= lookup_path_inherited(namespace, path, type) if inheritance namespace = namespace.parent end if proxy_fallback resolved ||= CodeObjects::Proxy.new(orignamespace, path, type) end resolved end |