Decode SourceDecodeSource

class Source

Represents a source file in a specific language.

Definitions

attr :path

The path of the source file.

Signature

attribute String

A file-system path.

def relative_path

The relative path of the source, if it is known.

Implementation

def relative_path
	if @path.respond_to?(:relative_path)
		@path.relative_path
	else
		@path
	end
end

attr :language

The language of the source file.

Signature

attribute Language::Generic

def read

Read the source file into an internal buffer/cache.

Signature

returns String

Implementation

def read
	@buffer ||= File.read(@path).freeze
end

def definitions(&block)

Open the source file and read all definitions.

Signature

yields {|definition| ...}

All definitions from the source file.

parameter definition Definition
returns Enumerator(Definition)

If no block given.

Implementation

def definitions(&block)
	return to_enum(:definitions) unless block_given?
	
	@language.definitions_for(self, &block)
end

def segments(&block)

Open the source file and read all segments.

Signature

yields {|segment| ...}

All segments from the source file.

parameter segment Segment
returns Enumerator(Segment)

If no block given.

Implementation

def segments(&block)
	return to_enum(:segments) unless block_given?
	
	@language.segments_for(self, &block)
end