class Redoc::Library
- Redoc::Library
- Reference
- Object
Overview
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.
Included Modules
- JSON::Serializable
- Redoc::Namespace
Defined in:
redoc/types.crConstructors
Instance Method Summary
-
#description : String
The description of the library.
-
#macros : Array(Macro)
An array of top-level macros.
-
#methods : Array(Def)
An array of top-level methods.
-
#name : String
The name of the library.
-
#resolve(pattern : String) : Type
Resolves a query pattern to a type in the library.
-
#resolve?(namespace : Array(String), symbol : String | Nil, scope : QueryScope) : Type | Nil
Same as
#resolve?
using unparsed inputs. -
#resolve?(pattern : String) : Type | Nil
Same as
#resolve
but returnsnil
if no type or symbol is found. -
#resolve_all(namespace : Array(String), symbol : String, scope : QueryScope) : Array(Type)
Same as
#resolve_all
using unparsed inputs. -
#resolve_all(pattern : String) : Array(Type)
Resolves all types in a library from a query pattern.
Instance methods inherited from module Redoc::Namespace
aliases : Array(Alias)
aliases,
aliases=(aliases : Array(Alias))
aliases=,
annotations : Array(Annotation)
annotations,
annotations=(annotations : Array(Annotation))
annotations=,
classes : Array(Class)
classes,
classes=(classes : Array(Class))
classes=,
constants : Array(Const)
constants,
constants=(constants : Array(Const))
constants=,
enums : Array(Enum)
enums,
enums=(enums : Array(Enum))
enums=,
html_id : String
html_id,
html_id=(html_id : String)
html_id=,
modules : Array(Module)
modules,
modules=(modules : Array(Module))
modules=,
path : String
path,
path=(path : String)
path=,
structs : Array(Struct)
structs,
structs=(structs : Array(Struct))
structs=
Constructor Detail
Instance Method Detail
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:...>, ...]