class

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

new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Instance methods

description

The description of the library.

Source
macros

An array of top-level macros.

Source
methods

An array of top-level methods.

Source
name

The name of the library.

Source
resolve(pattern : String) : Type

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:...>
Source
resolve?(namespace : Array(String), symbol : String | Nil, scope : QueryScope) : Type | Nil

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:...>
Source
resolve?(pattern : String) : Type | Nil

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
Source
resolve_all(namespace : Array(String), symbol : String, scope : QueryScope) : Array(Type)

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).

Source
resolve_all(pattern : String) : Array(Type)

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:...>, ...]
Source