Redoc::Library
Inherits Redoc::Namespace < JSON::Serializable < Reference < Object
Represents a library (known as Program in the Crystal compiler). This contains the name and description of the library, top-level definitions (constants, macros and methods), and encapsulates all types defined and documented in the library.
Constructors
Instance methods
Resolves a query pattern to a type in the library. This uses the Crystal path format to denote constants from symbols/identifiers. Raises if the pattern is invalid or no type or symbol is found.
require "redoc"
library = File.open "./source.json" do |file|
Redoc.load file
end
library.resolve "VERSION" # => #<Redoc::Const:...>
Same as resolve? using unparsed inputs. The namespace is an array of strings
representing the namespace path. The symbol is an identifier or operator and
scope is an enum value representing how symbol should be looked up. Returns
nil if no type or symbol is found in the given namespace.
WARNING: in most if not all cases you should use resolve? to ensure that input
parameters are correctly parsed. This method does not do additional parsing or
validation of input parameters.
When scope is set to QueryScope::Class only class methods (including
constructors) and macros will be looked up, when set to QueryScope::Instance only
instance methods are looked up, and when set to QueryScope::All both are checked.
Note that QueryScope::TopLevel has no effect in this method.
require "redoc"
library = File.open "./source.json" do |file|
Redoc.load file
end
library.resolve?(["Regex"], "=~", :class) # => nil
library.resolve?(["Regex"], "=~", :instance) # => #<Redoc::Def:...>
Same as resolve but returns nil if no type or symbol is found.
WARNING: this method can stil raise if the pattern is not in valid Crystal path format.
require "redoc"
library = File.open "./source.json" do |file|
Redoc.load file
end
library.resolve? "UNKNOWN" # => nil
library.resolve? "::unknown" # => raises Exception
Same as resolve_all using unparsed inputs. The same scope semantics as resolve?
also apply in this method with one exception: QueryScope::TopLevel will only
check top-level methods (that is, methods and macros in the Library).
Resolves all types in a library from a query pattern. This uses the Crystal path format to denote constants from symbols/identifiers. Raises if the pattern is invalid.
require "redoc"
library = File.open "./source.json" do |file|
Redoc.load file
end
library.resolve_all "Any" # => [#<Redoc::Struct:...>, ...]