DecodeSourceDecodeDefinition

class Definition

A symbol with attached documentation.

Definitions

def initialize(path, parent: nil, language: parent&.language, comments: nil, visibility: :public, source: parent&.source)

Initialize the symbol.

Signature

parameter path Symbol | Array(Symbol)

The path of the definition relatve to the parent.

parameter parent Symbol

The parent lexical scope.

parameter language Language

The language in which the symbol is defined in.

parameter comments Array(String)

The comments associated with the definition.

parameter source Source

The source file containing this definition.

Implementation

def initialize(path, parent: nil, language: parent&.language, comments: nil, visibility: :public, source: parent&.source)
	@path = Array(path).map(&:to_sym)
	
	@parent = parent
	@language = language
	@source = source
	
	@comments = comments
	@visibility = visibility
	
	@full_path = nil
	@qualified_name = nil
	@nested_name = nil
end

def inspect

Generate a debug representation of the definition.

Implementation

def inspect
	"\#<#{self.class} #{qualified_name}>"
end

alias to_s inspect

Generate a string representation of the definition.

def name

The symbol name. e.g. :Decode.

Signature

attribute Symbol

Implementation

def name
	@path.last
end

attr :path

Signature

attribute Array(Symbol)

The path to the definition, relative to the parent.

def full_path

The full path to the definition.

Implementation

def full_path
	@full_path ||= begin
		if @parent
			@parent.full_path + @path
		else
			@path
		end
	end
end

alias lexical_path full_path

The lexical path to the definition (full path including all namespaces).

Signature

returns Array(Symbol)

The complete path from root to this definition.

attr :parent

Signature

attribute Definition | Nil

The parent definition, defining lexical scope.

attr :language

Signature

attribute Language::Generic

The language the symbol is defined within.

attr :source

Signature

attribute Source | Nil

The source file containing this definition.

attr :comments

Signature

attribute Array(String)

The comment lines which directly preceeded the definition.

def public?

Whether the definition is considered part of the public interface. This is used to determine whether the definition should be documented for coverage purposes.

Signature

returns Boolean

True if the definition is public.

Implementation

def public?
	true
end

def documented?

Whether the definition has documentation.

Signature

returns Boolean

True if the definition has non-empty comments.

Implementation

def documented?
	@comments&.any?
end

def qualified_name

The qualified name is an absolute name which includes any and all namespacing.

Signature

returns String

Implementation

def qualified_name
	@qualified_name ||= begin
		if @parent
			[@parent.qualified_name, self.nested_name].join("::")
		else
			self.nested_name
		end
	end
end

def nested_name

The name relative to the parent.

Signature

returns String

Implementation

def nested_name
	@nested_name ||= "#{@path.join("::")}"
end

def start_with?(prefix)

Does the definition name match the specified prefix?

Signature

returns Boolean

Implementation

def start_with?(prefix)
	self.nested_name.start_with?(prefix)
end

def convert(kind)

Convert this definition into another kind of definition.

Implementation

def convert(kind)
	raise ArgumentError, "Unable to convert #{self} into #{kind}!"
end

def short_form

A short form of the definition. e.g. def short_form.

Signature

returns String | nil

Implementation

def short_form
end

def long_form

A long form of the definition. e.g. def initialize(kind, name, comments, **options).

Signature

returns String | nil

Implementation

def long_form
	self.short_form
end

def qualified_form

A long form which uses the qualified name if possible. Defaults to Decode::Definition#long_form.

Signature

returns String | nil

Implementation

def qualified_form
	self.long_form
end

def multiline?

Whether the definition spans multiple lines.

Signature

returns Boolean

Implementation

def multiline?
	false
end

def text

The full text of the definition.

Signature

returns String | nil

Implementation

def text
end

def container?

Whether this definition can contain nested definitions.

Signature

returns Boolean

Implementation

def container?
	false
end

def nested?

Whether this represents a single entity to be documented (along with it's contents).

Signature

returns Boolean

Implementation

def nested?
	container?
end

def documentation

Structured access to the definitions comments.

Signature

returns Documentation | Nil

A class Decode::Documentation instance if this definition has comments.

Implementation

def documentation
	if @comments&.any?
		@documentation ||= Documentation.new(@comments, @language)
	end
end

def location

The location of the definition.

Signature

returns Location | Nil

A class Decode::Location instance if this definition has a location.

Implementation

def location
	nil
end

attr_accessor :visibility

The visibility of the definition.

Signature

attribute Symbol

:public, :private, :protected