struct Bindgen::Graph::Path

Overview

Pathing logic for the graph. See Path.local to find a locally-qualified path between two nodes. Or use .from to build a path from a string.

The structure doesn't store any origin by itself.

Defined in:

bindgen/graph/path.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from(path : String) : Path #

Returns a new Path on path. Supports generic parts.


[View source]
def self.from(path : Path) : Path #

Returns a new Path on path. Supports generic parts.


[View source]
def self.from(paths : Enumerable(String | Path)) : Path #

Returns a new Path formed by concatenating the given paths. An empty collection produces a self-path.


[View source]
def self.from(first_path : String | Path, *remaining : String | Path) : Path #

Returns a new Path formed by concatenating the given paths. An empty collection produces a self-path.


[View source]
def self.global(node : Node) : Path #

Returns the global path to node.


[View source]
def self.global_root : Path #

Returns a path that refers to the global root.


[View source]
def self.local(from node : Node, to wants : Node) : Path #

Finds the local path to go from node to wants, in terms of constant resolution for Crystal.

Each call may perform multiple look-ups to ensure the resulting local path refers to wants unambiguously. If this cannot be done, a global path will be returned.


[View source]
def self.self_path : Path #

Returns a self-referencing path.


[View source]

Instance Method Detail

def ==(other : self) #

def [](range : Range) : Path #

Returns the Path with the parts in range. The new Path is global only if it includes the first part of this Path and this Path is also global.


[View source]
def empty?(*args, **options) #

Is this an empty path?


[View source]
def empty?(*args, **options, &) #

Is this an empty path?


[View source]
def global? : Bool #

Is this a global path?


[View source]
def hash(hasher) #
Description copied from struct Struct

See Object#hash(hasher)


def inspect(io) #

Much like #to_s, but tells the user when this path points to itself.


[View source]
def join(other : Path) : Path #

Combines the other path into this path. If the other path is global, simply returns other. Otherwise, the new path contains the parts from this path, followed by the parts from other.


[View source]
def last : Path #

Returns the local Path with only the last part in #nodes, thus pointing at the child in #parent. Raises if this is an empty path.


[View source]
def last_part : String #

Returns the last part of this path. Raises if this is an empty path.


[View source]
def local? #

Is this a local path? Also true if this is a #self_path? path.


[View source]
def lookup(base : Node) : Node | Nil #

Does a local look-up starting at base for path. The look-up will begin in base itself. If not found, it'll try to find the path by going up to the parent(s).

If the path starts with :: (An empty element), the look-up will always start at the global scope. If path is exactly ::, the root node (not the global root) is returned. Otherwise, the first part of the path must be the name of the root node: ::RootName::And::So::On instead of ::And::So::On.

If not found, returns nil. This method does not raise.


[View source]
def parent : Path #

Returns the Path excluding the last part in #nodes, thus pointing to the parent of this path. Returns a global path if this path is also global. Raises if this is an empty path.


[View source]
def parts : Array(String) #

The names of the path at each namespace.


[View source]
def self_path? #

Does this path point to itself?


[View source]
def to_global(base : Node) : Path #

Returns a global path from this local path, starting look-up at base. Does a full look-up under the hood, thus, the path has to be valid.

If this is already a #global? path, it is returned without further checks.


[View source]
def to_s(io) #

Gives the path as Crystal constants look-up path.


[View source]