class Crodoc::Source

Overview

Represents a Crystal source file.

Defined in:

crodoc/source.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(code : String, path : String) #

Creates a new source using #code and #path.

Example:

path = "./src/source.cr"
Crodoc::Source.new(File.read(path), path)

[View source]

Instance Method Detail

def ast #

Returns AST nodes constructed by Crystal::Parser.

Example

source = Crodoc::Source.new(code, path)
source.ast

[View source]
def code : String #

Contents of the source file


[View source]
def fullpath #

The full, expanded path to the source file.


[View source]
def lines #

Returns the lines of code by splitting the #code by on newlines. Lines are cached and lazily loaded.

Example:

source = Crodoc::Source.new("a = 1\nb = 2", "")
source.lines # => ["a = 1", "b = 2"]

[View source]
def matches_path?(filepath) #

Returns true if filepath matches the source's path, false if it does not.


[View source]
def path : String #

Path to the source file


[View source]